Skip to content

Commit

Permalink
Implemented the new .slice() method (bug jquery#1517).
Browse files Browse the repository at this point in the history
  • Loading branch information
jeresig committed Aug 20, 2007
1 parent 2ef4093 commit 887c007
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/jquery/coreTest.js
Expand Up @@ -920,3 +920,11 @@ test("eq(), gt(), lt(), contains()", function() {
isSet( $("#ap a").lt(3).get(), q("google", "groups", "anchor1"), "lt()" );
isSet( $("#foo a").contains("log").get(), q("anchor2", "simon"), "contains()" );
});

test("slice()", function() {
expect(4);
isSet( $("#ap a").slice(1,2), q("groups"), "slice(1,2)" );
isSet( $("#ap a").slice(1), q("groups", "anchor1", "mark"), "slice(1)" );
isSet( $("#ap a").slice(0,3), q("google", "groups", "anchor1"), "slice(0,3)" );
isSet( $("#ap a").slice(-1), q("mark"), "slice(-1)" );
});
4 changes: 4 additions & 0 deletions src/jquery/jquery.js
Expand Up @@ -1160,6 +1160,10 @@ jQuery.fn = jQuery.prototype = {
( this.length ? this[0].innerHTML : null ) :
this.empty().append( val );
},

slice: function() {
return this.pushStack( Array.prototype.slice.apply( this, arguments ) );
},

/**
* @private
Expand Down

0 comments on commit 887c007

Please sign in to comment.