Skip to content
Permalink
Browse files

Added $(...).map() functionality. (Also closes #1250, imo)

  • Loading branch information
jeresig committed Aug 31, 2007
1 parent 5c19701 commit 079d651e10bc19a28c49945617e842415dc41981
Showing with 26 additions and 0 deletions.
  1. +20 −0 src/jquery/coreTest.js
  2. +6 −0 src/jquery/jquery.js
@@ -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"
);
});
@@ -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

0 comments on commit 079d651

Please sign in to comment.
You can’t perform that action at this time.