> There's been some rabble-rousing concerning the destructive
> nature of jQuery (it's ok, rousing is a good thing ;-)). I claimed
> that it'd be easy to have it exist as a plugin. Well, it took me
> all of 10 minutes, but here it is:
>
> jQuery.fn._pushStack = jQuery.fn.pushStack;
>               
> jQuery.fn.pushStack = function(){
>     var ret = jQuery.fn._pushStack.apply( jQuery(this), arguments );
>     ret.prevObject = this;
>     return ret;
> };
>               
> jQuery.fn.end = function(){
>     return this.prevObject || jQuery([]); };
> 
> You can see a demo (requires Firebug) here:
> http://john.jquery.com/jquery/test/destruct.html

Your ideas intrigue me and I'd like to subscribe to your newsletter. :)

Just an optimization, but it would be good to have the
.destructiveMethod(selector, function) case not create a new object since it
doesn't (permanently) change the original object. It looks like _pushStack
will stack the old jQuery object's nodes in the new jQuery object, which it
won't use. The internal stack has been replaced by the prevObject chain,
which is a good thing because it makes earlier states easily accessible via
simple object references. Before, we couldn't get to the internal stack
without .end()ing.



_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/

Reply via email to