🌐 AI搜索 & 代理 主页
Skip to content

Commit e532dfe

Browse files
committed
Add support for .get(-Number) Closes #4188
1 parent e124fec commit e532dfe

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/core.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,10 @@ jQuery.fn = jQuery.prototype = {
130130
return num == null ?
131131

132132
// Return a 'clean' array
133-
Array.prototype.slice.call( this ) :
133+
this.toArray() :
134134

135135
// Return just the object
136-
this[ num ];
136+
( num < 0 ? this.toArray.call(this, num)[0] : this[ num ] );
137137
},
138138

139139
// Take an array of elements and push it onto the stack

test/unit/core.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,13 @@ test("get(Number)", function() {
340340
equals( jQuery("p").get(0), document.getElementById("firstp"), "Get A Single Element" );
341341
});
342342

343+
test("get(-Number)",function() {
344+
expect(1);
345+
equals( jQuery("p").get(-1),
346+
document.getElementById("first"),
347+
"Get a single element with negative index" )
348+
})
349+
343350
test("add(String|Element|Array|undefined)", function() {
344351
expect(12);
345352
isSet( jQuery("#sndp").add("#en").add("#sap").get(), q("sndp", "en", "sap"), "Check elements from document" );

0 commit comments

Comments
 (0)