My Favorite jQuery Plugin Template
kolodny.github.io
kolodny.github.io
It seems a lot clearer to simply declare `var pluginName = "borderize";` at the top of the function than to pass it in. Granted, that does add 6 characters to the total length of the file.
Isn't a little bit inconvinient, talking about modularity, will you be the only one using those plugins?
var borderize = require('jquery.borderize');
...
borderize('div');
And my linter will tell me off if I forget a require.Edit: I guess such a thing is not really a 'jQuery plugin' but a 'module that depends on jQuery'.
Actually that's better because if one of the options is an object I wouldn't have to worry about accidentally changing a propery because this does a deep copy.
I've updated the post, thanks.
Personally, I find the "that" variable to be a little confusing. A developer looking at the code might wonder whether "that" is the plugin, a DOM element, or something else. To make the code a little clearer, you could use something like "elem" to represent the element on which the plugin has been called, and "plugin" to represent the plugin itself.
Happy coding!
Thanks
;!function($){
...
return this.each(function($elem, elem){
$elem = $(elem);
...
});
...
}(jQuery);