Opened 16 years ago
Closed 15 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 )
reverse:
jQuery.fn.reverse = function() { return this.pushStack(this.get().reverse(), arguments); };
sort:
jQuery.fn.sort = function() { return this.pushStack( [].sort.apply( this, arguments ), []); };
Change History (7)
comment:1 Changed 16 years ago by
comment:3 Changed 16 years ago by
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 16 years ago by
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 16 years ago by
Component: | → core |
---|---|
need: | → Review |
Owner: | set to john |
Priority: | → minor |
Type: | → feature |
comment:6 Changed 15 years ago by
Description: | modified (diff) |
---|
This has no use for the core, so shall I close this ?
comment:7 Changed 15 years ago by
Resolution: | → invalid |
---|---|
Status: | new → closed |
Ticket #320 suggests a way to obviate these additional functions: having
jQuery.fn
inherit explicitly fromArray
.