Skip to content

Instantly share code, notes, and snippets.

@zhang6464
Created October 11, 2014 11:12
Show Gist options
  • Save zhang6464/377f34c479e01b65a2eb to your computer and use it in GitHub Desktop.
Save zhang6464/377f34c479e01b65a2eb to your computer and use it in GitHub Desktop.
javascript Array.prototype.map implement.
!function(){
if( typeof Array.prototype.map == 'function')
return;
Array.prototype.map = function(callback){
var i = 0,
length = this.length,
res = [];
if( callback && typeof callback == 'function' ){
for(;i<length;i++)
res[i] = callback(this[i]);
}
return res;
}
}();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment