Hi all,
As promised, here is the second topic I wanted to ask about:
Are there any plans, or is there any current way to subclass the  
jQuery object? I've been doing a lot of digging around and I've seen  
some talks about it, and there have been some questions about what the  
use would be, but I've found a use case, and me, Paul, and Eduardo  
have all tried to figure out a way, but to no avail.

Here is the use case:
I want to create a function that behaves exactly like jQuery, except  
that it does some slightly different things, and be able to extend it  
without worrying about what the parent jQuery object is doing, or what  
plugins have been loaded globally.
The benefits are that it would use the prototype chain, so it would be  
memory efficient, and it would be a way to add plugins without them  
being clobbered by other plugins.

So, I've tried a bunch of stuff:
var subClass = function(sel, context){
  return new subClass.fn.init(sel, context);
}

subClass.fn = subClass.prototype = new jQuery.fn.init;
subClass.fn.init = subClass.prototype;

and I've tried so many different variations of this, but anytime I try  
to do:
subClass.fn.test = function(){}

it, without fail, creates jQuery.fn.test.

To show what I am trying to do, I'll give an example:

jQuery.fn.plugin1 = function(){
console.log('I am global, everyone can see me');
return this;
} // globally available plugin

subClass.fn.plugin1 = function(){
console.log('I am local, and I am only run when using the subclass');
return this;
} // my own local plugin

so you could do:
jQuery('body').plugin1(); // prints 'I am global, everyone can see me'
subClass('body').plugin1(); // prints 'I am local, and I am only run  
when using the subclass'

However, namespaced plugins is only one advantage. Being able to  
attach custom static methods, etc, would be incredibly useful.

Does anyone know of a way to subclass the jQuery object using it's  
prototype?

Thanks again for reading all of this. I truly appreciate it,

Nate Cavanaugh
Director of User Interface Engineering
Liferay, Inc.
Enterprise. Open Source. For life.








Nate Cavanaugh
Director of User Interface Engineering
Liferay, Inc.
Enterprise. Open Source. For life.






--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to