javascript - Attaching new plugin to $ or not? -
i wrote plugin ( uses jquery).
should attach jquery's dollar sign ?
$.myplugin=... or should i attach window.myplugin=... ?
of course plugins won't work without jquery . mean should create god object($) , attach ( dollar sign). ?
(assuming $ single library object on page)
per jquery site, should attach jquery object, not $ (which may or may not reused). see http://learn.jquery.com/plugins/basic-plugin-creation/ .
note typical pattern use $ alias within definition:
(function ( $ ) { // jquery recommends avoiding more 1 instance method, instead taking // parameter, or better yet, extensible options object: $.fn.instancemethod = function(options) { //... return this; }; $.classmethod = function () { //.... }; }( jquery ));
Comments
Post a Comment