Implemented the new .slice() method (bug #1517).
authorJohn Resig <jeresig@gmail.com>
Mon, 20 Aug 2007 02:51:57 +0000 (02:51 +0000)
committerJohn Resig <jeresig@gmail.com>
Mon, 20 Aug 2007 02:51:57 +0000 (02:51 +0000)
src/jquery/coreTest.js
src/jquery/jquery.js

index 289a416..ff8909c 100644 (file)
@@ -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)" );
+});
index b7091e2..ff33034 100644 (file)
@@ -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