jQuery dễ dàng-sử dụng cú pháp phát triển dẫn đến sự bắt đầu viết kịch bản để đạt được các hiệu ứng tùy chỉnh và các nhiệm vụ khác. Để thực hiện các kịch bản cấu hình và tái sử dụng, các nhà phát triển xây dựng các kịch bản này là phần bổ trợ, hoặc các kịch bản mở rộng jQuery bằng cách thêm các phương pháp mới vào thư viện. | C H A P T E R 10 Extending jQuery jQuery s easy-to-use syntax led developers to begin writing scripts to achieve custom effects and other tasks. To make these scripts configurable and reusable these developers constructed these scripts as plugins or scripts that extend jQuery by adding new methods to the library. In this chapter you ll learn how to add your own plugins to jQuery. Adding Functions to jQuery In some cases it may be desirable to add a function directly to the jQuery object which means you would be able to call it like so .yourFunction Adding functions to jQuery can help you keep your scripts organized and ensure that your function calls follow a consistent format. However it s important to note that adding a function to jQuery does not allow you to chain it with a set of selected DOM elements for this you must use a method which you ll learn how to do in this chapter. Adding Your Date Validation Function to jQuery In your first extending jQuery example you will add the date validation function you wrote in the last chapter to the jQuery object. Specifically you ll leverage . Allowing Custom Aliases in jQuery Plugins One thing you should consider is allowing custom aliases in your jQuery plugins. While this isn t strictly necessary it is strongly encouraged because it can help you keep your plugin from breaking if the shortcut is given up by . Better still this feature is so simple to implement that it s actually a little silly not to include it. When building a new plugin you should put the plugin code within a function that is executed immediately when the script is loaded. At its outset the script should look like this 345 CHAPTER 10 EXTENDING JQUERY function plugin code here. The second set of parentheses causes the preceding code to be executed immediately as a function which is where the custom alias comes in. If you pass the jQuery object to the second set of parentheses and the shortcut to the internal function .