Bug Tracker

Opened 10 years ago

Closed 9 years ago

#255 closed feature (invalid)

Add reverse and sort to jQuery core

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

Description (last modified by flesler)


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


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

Change History (7)

comment:1 Changed 10 years ago by henra..h+jqu

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

comment:2 Changed 10 years ago by www.gewinnsp


comment:3 Changed 10 years ago by Erik

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?

comment:4 Changed 10 years ago by Erik

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 )) );


comment:5 Changed 10 years ago by john

  • Component set to core
  • need set to Review
  • Owner set to john
  • Priority set to minor
  • Type set to feature

comment:6 Changed 9 years ago by flesler

  • Description modified (diff)

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

comment:7 Changed 9 years ago by flesler

  • Resolution set to invalid
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.