Please activate JavaScript!
Please install Adobe Flash Player, click here for download

SAE Magazine

// File: 06-plugin-on-prototype.js (function($, window, undefined) { $.fn.pluginName = function() { return this.each(function() { // plugin logic }); } })(jQuery, window); As you can see, we do not add our pluginName directly to the $, but to its fn property which is the shortcut for jQuery’s prototype. The plugin itself is a function, which returns this. But for each this we’ll execute another function, which is the plugin logic we want to execute. We need to use each because calls like $(‘ul li’) usually return multiple objects. So this.each will execute a function for any of the found li’s like: $(‘ul li’).pluginName(); Because of implementing chainability, any jQuery user will be able to continue working with the objects: $(‘ul li’).pluginName().show(); ➤ INDEX approaches to add some- one you should choose nt to do with it. d a simple function, which o with any DOM elements. e jQuery object itself like nction.js efined) { age) { ssage); () from anywhere in your plugin file. e of plugin doesn’t usually hence it is not chainable usage. You can see more g like $.ajax(). plugin for use on DOM extend the jQuery Proto- Query object instance will for chainability. See how

Pages