> jQuery.fn.reverse = function() {
>  this.pushStack(this.get().reverse());
>  return this;
> }

Huh, at first I though that that code would infinitely recurse, I
totally forgot that .get() returns a "clean" array of elements - good
call! Just a quick simplification:

jQuery.fn.reverse = function() {
  return this.pushStack(this.get().reverse(), arguments);
};

going through the other functions, you can easily do .sort() and the
other functions too:

jQuery.fn.sort = function() {
  return this.pushStack( [].sort.apply( this, arguments ), []);
};

// These don't quite work correctly - but making them work "correctly" would
//  break jQuery (having duplicate instances of an element)
jQuery.fn.push = jQuery.fn.add;
jQuery.fn.unshift = jQuery.fn.unshift;

jQuery.fn.slice = function() {
  return this.pushStack( [].slice.apply( this, arguments ), arguments );
};

jQuery.fn.pop = function(fn){
  return this.slice( 0, -1, fn );
};

jQuery.fn.shift = function(fn){
  return this.slice( 1, this.length, fn );
};

I can definitely see .sort() and .reverse() being useful - along with
a better version of slice, but push, pop, shift, unshift are all kind
of lame (IMO).

--John

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

Reply via email to