Skip to content

Commit

Permalink
Added $(...).map() functionality. (Also closes #1250, imo)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeresig committed Aug 31, 2007
1 parent 5c19701 commit 079d651
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/jquery/coreTest.js
Expand Up @@ -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 changes: 6 additions & 0 deletions src/jquery/jquery.js
Expand Up @@ -1189,6 +1189,12 @@ jQuery.fn = jQuery.prototype = {
slice: function() {
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
Expand Down

0 comments on commit 079d651

Please sign in to comment.