mirror of
https://github.com/jquery/jquery.git
synced 2024-11-23 02:54:22 +00:00
Added $(...).map() functionality. (Also closes #1250, imo)
This commit is contained in:
parent
5c19701a89
commit
079d651e10
20
src/jquery/coreTest.js
vendored
20
src/jquery/coreTest.js
vendored
@ -976,3 +976,23 @@ test("slice()", function() {
|
||||
isSet( $("#ap a").slice(0,3), q("google", "groups", "anchor1"), "slice(0,3)" );
|
||||
isSet( $("#ap a").slice(-1), q("mark"), "slice(-1)" );
|
||||
});
|
||||
|
||||
test("map()", function() {
|
||||
expect(2);
|
||||
|
||||
isSet(
|
||||
$("#ap").map(function(){
|
||||
return $(this).find("a").get();
|
||||
}),
|
||||
q("google", "groups", "anchor1", "mark"),
|
||||
"Array Map"
|
||||
);
|
||||
|
||||
isSet(
|
||||
$("#ap > a").map(function(){
|
||||
return this.parentNode;
|
||||
}),
|
||||
q("ap","ap","ap"),
|
||||
"Single Map"
|
||||
);
|
||||
});
|
||||
|
6
src/jquery/jquery.js
vendored
6
src/jquery/jquery.js
vendored
@ -1190,6 +1190,12 @@ jQuery.fn = jQuery.prototype = {
|
||||
return this.pushStack( Array.prototype.slice.apply( this, arguments ) );
|
||||
},
|
||||
|
||||
map: function(fn){
|
||||
return this.pushStack(jQuery.map( this, function(elem,i){
|
||||
return fn.call( elem, i, elem );
|
||||
}));
|
||||
},
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @name domManip
|
||||
|
Loading…
Reference in New Issue
Block a user