Usefulness of extending jQuery core -


i discovered method of extending core jquery init function (which gets called anytime use $() or jquery() function). not possible using ordinary proxy pattern following code makes work:

var originit = jquery.fn.init;  jquery.fn.init = function(selector, context, rootjquery) {     if (some condition) {         //custom code here, possibly returning other jquery object         //what jquery return     }     return originit.call(jquery.fn, selector, context, rootjquery); } 

my question might useful, since realized initial intent of using caching of selectors problematic (since affect behavior of other plugins -- ended using separate function caching).

so thought i'd share method , i'm curious hear other ideas potential uses of it. thought maybe used support custom selectors of kind, although i'm not sure when needed since jquery offers lot of selectors.

you find jquery has method build around concept.

jquery.sub()

this allows extend jquery locally without "corrupting" or "altering" global jquery object.

from personal experimentation find jquery complex alter init function without dealing kinds of nasty edge cases. it's far better create factory decoration method around jquery object.

there many uses changing jquery methods or constructor ranging logging injecting custom logic writing guid onto jquery objects.


Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -