In both cases, you add a function to the jQuery global object, which allows you to call $.pluginName .
# 1 also adds a plugin to all the jQuery element objects that you get when you call the $ : $("#selector") function.
Perhaps your plugin returns a jQuery element object. So first you use $.pluginName , and in the following code you call $.fn.pluginName . You cannot bind C # 2 calls because $.fn.pluginName is undefined.
This will make sense if you know that $.fn is an alias for $.prototype . (The prototype functions are members of all $() return values — using the new keyword in the background.)
You can create an object with all your plugins to simplify the code:
var plugins = { myPlugin: function(){}, myPlugin2: function(){} } $.extend($, plugins); $.extend($.fn, plugins);
source share