Bug Tracker

Ticket #255 (closed feature: invalid)

Opened 9 years ago

Last modified 7 years ago

Add reverse and sort to jQuery core

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

Description (last modified by flesler) (diff)


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


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

Change History

comment:1 Changed 9 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 9 years ago by www.gewinnsp


comment:3 Changed 9 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 9 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 8 years ago by john

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

comment:6 Changed 7 years ago by flesler

  • Description modified (diff)

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

comment:7 Changed 7 years ago by flesler

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