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 comment:1
Changed November 22, 2006 10:10PM UTC by comment:2
!
Changed December 21, 2006 03:54AM UTC by 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 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 comment:5
component: | → core |
---|---|
need: | → Review |
owner: | → john |
priority: | → minor |
type: | → feature |
Changed May 11, 2008 11:36PM UTC by 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 comment:7
resolution: | → invalid |
---|---|
status: | new → closed |
Ticket #320 suggests a way to obviate these additional functions: having
jQuery.fn
inherit explicitly fromArray
.