I've actually created a 'plugin' for authoring advanced plugins such as this.
It allows for custom namespaces while still using 'this' inside them to refer to the jQuery object selection. On top of just namespaces, it also has methods to remove plugins, check to see if one exists and one for assigning plugin options to specific dom objects as well as function names that have 'magic' functionality. When checking for existence, it only takes into account "plugins", meaning anything added via jQuery.plugin.add() or jQuery.fn.plugin.add(). I won't go into it much here, but the code is very well documented: http://code.google.com/p/jquery-plugin-dev/source/browse/trunk/jquery.plugin.js ...and, please, feel free to email me with any questions, or if you want to help out with the project. -Trey On Mar 29, 2:01 am, Howard Rauscher <[email protected]> wrote: > I tried to do something like this a couple of months ago, and you > really can't do it efficiently. This method is the only real way to > do it > > "$('div ul').myNamespace().myMethod();" > > And it is pretty messy. > > If you really wanted to do it this way "$('div > ul').myNamespace.myMethod()," you would have to bind the scope of each > $ call to each method that is apart of your myNamespace object. > > You could also make you own static method that uses a jQuery object > with your methods. > > $.myNamespace = function(selector) { > this.instance = $(selector);}; > > myNamespace.prototype = { > myMethod : function() { > //do what ever > // this.instance will be the jQuery object > } > > }; > > On Mar 28, 7:58 am, Julian Aubourg <[email protected]> wrote: > > > I don't think it is possible. No matter how you turn it around, you'll lose > > the object context. > > > I suppose your myNamespace() function is something like: > > > $.fn.myNamespace = function() { > > return this; > > > } > > > right? > > > 2009/3/28 iceman2g <[email protected]> > > > > I asked this elsewhere and it was suggested that I ask here. > > > > So here goes > > > > I was curious if it's possible to extend jquery to do something along > > > the > > > lines of "$('div ul').myNamespace.myMethod();"? > > > > So far the closet I've seen anyone come to this, is along the lines of > > > "$('div ul').myNamespace().myMethod();". --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "jQuery Development" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/jquery-dev?hl=en -~----------~----~----~----~------~----~------~--~---
