Skip to main content

Bug Tracker

Side navigation

#255 closed feature (invalid)

Opened October 07, 2006 10:24PM UTC

Closed July 23, 2008 04:31PM UTC

Add reverse and sort to jQuery core

Reported by: joern Owned by:
Priority: minor Milestone:
Component: core Version:
Keywords: Cc:
Blocked by: Blocking:
Description

reverse:

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

sort:

jQuery.fn.sort = function() {
  return this.pushStack( [].sort.apply( this, arguments ), []);
};
Attachments (0)
Change History (7)

Changed October 29, 2006 08:36AM UTC by henra..h+jqu comment:1

Ticket #320 suggests a way to obviate these additional functions: having jQuery.fn inherit explicitly from Array.

Changed November 22, 2006 10:10PM UTC by www.gewinnsp comment:2

!

Changed December 21, 2006 03:54AM UTC by Erik comment:3

This breaks in jQuery 1.0.4 with the following error:

second argument to Function.prototype.apply must be an array

Which happens down in set(), called from pushStack. Apparently, the array returned from apply isn't array enough to pass into apply down in set. I fixed it by wrapping the sort.apply() with merge:

jQuery.fn.sort = function() {

return this.pushStack( jQuery.merge( [].sort.apply( this, arguments ), []), [] );

};

I'm wondering if this is behavior that should be incorporated into the set() function? Are there other things expecting to pass not-quite-array objects to pushStack and have them dealt with properly?

Changed January 16, 2007 10:44AM UTC by Erik comment:4

This also broke with 1.1, exactly the same way it did with 1.0.4. This seems to work with 1.1:

jQuery.fn.sort = function() {

return this.pushStack( jQuery.makeArray( [].sort.apply( this, arguments )) );

};

Changed March 26, 2007 03:14PM UTC by john comment:5

component: → core
need: → Review
owner: → john
priority: → minor
type: → feature

Changed May 11, 2008 11:36PM UTC by flesler comment:6

description: reverse:\ {{{\ jQuery.fn.reverse = function() {\ return this.pushStack(this.get().reverse(), arguments);\ };\ }}}\ \ sort:\ {{{\ jQuery.fn.sort = function() {\ return this.pushStack( [].sort.apply( this, arguments ), []);\ };\ }}}reverse: \ {{{ \ jQuery.fn.reverse = function() { \ return this.pushStack(this.get().reverse(), arguments); \ }; \ }}} \ \ sort: \ {{{ \ jQuery.fn.sort = function() { \ return this.pushStack( [].sort.apply( this, arguments ), []); \ }; \ }}}

This has no use for the core, so shall I close this ?

Changed July 23, 2008 04:31PM UTC by flesler comment:7

resolution: → invalid
status: newclosed