namespaces - Is attaching functions to the jQuery object bad practice? -
Currently I have a jQuery plugin that not only sets my function in $ .fn
$
, if (typeof (this) == 'function')
to see if it's $ .pliname
or $ (Elm). Plugin
... this is bad behavior, and if so, is there a better way to provide alternatives to the element?
jquery extension work is appearing on both namespaces:
jQuery sources Both define:
$ .extend = $ .fn.extend = ...
This will inspire me to believe that they Support your intentions to be able to do this. However, if you have established your functions to use both of the way jQuery authors, then you can get a better idea of the best practice. For example, you usually want $ .fn function to call function $ (like $ .data function in jQuery source)
$. Expansion ({Data: Function (AMM, Key, Value) {...}});
And (a bit simplified):
$ Fn.extend ({data: function (key, value) {return.Each (function () ($ .data (this, key, value);}}}})
this By the way, calls each other and takes care of the check for which you are using, and if you wanted, you can check for an undefined 'elem' ultimate in the $ namespace.
Comments
Post a Comment