aboutsummaryrefslogtreecommitdiffstats
path: root/src/core.js
diff options
context:
space:
mode:
authorRichard Gibson <richard.gibson@gmail.com>2012-10-19 17:08:50 -0400
committerDave Methvin <dave.methvin@gmail.com>2012-10-19 22:32:25 -0400
commitb5084b4bf29a2e517b90d5e7d82ed17c94a71d94 (patch)
tree63e72ba93a2dff1a43920e9ac48b243281acd56f /src/core.js
parent32051e97c1e77d0b678648832d090168b534841c (diff)
downloadjquery-b5084b4bf29a2e517b90d5e7d82ed17c94a71d94.tar.gz
jquery-b5084b4bf29a2e517b90d5e7d82ed17c94a71d94.zip
Fix #4262: faster .eq(), closes gh-1000.
Diffstat (limited to 'src/core.js')
-rw-r--r--src/core.js15
1 files changed, 7 insertions, 8 deletions
diff --git a/src/core.js b/src/core.js
index 2f5908b55..907e40eb1 100644
--- a/src/core.js
+++ b/src/core.js
@@ -234,11 +234,9 @@ jQuery.fn = jQuery.prototype = {
return this;
},
- eq: function( i ) {
- i = +i;
- return i === -1 ?
- this.slice( i ) :
- this.slice( i, i + 1 );
+ slice: function() {
+ return this.pushStack( core_slice.apply( this, arguments ),
+ "slice", core_slice.call(arguments).join(",") );
},
first: function() {
@@ -249,9 +247,10 @@ jQuery.fn = jQuery.prototype = {
return this.eq( -1 );
},
- slice: function() {
- return this.pushStack( core_slice.apply( this, arguments ),
- "slice", core_slice.call(arguments).join(",") );
+ eq: function( i ) {
+ var len = this.length,
+ j = +i + ( i < 0 ? len : 0 );
+ return this.pushStack( j >= 0 && j < len ? [ this[j] ] : [] );
},
map: function( callback ) {