Posted By

hand4ever on 06/30/10


Tagged

javascript curring


Versions (?)

currying in javascript


 / Published in: JavaScript
 

each in Array,It can operate each element in Array. e.g. var result = [1,2,3,4].each(function(x){return Math.sqrt(x);}); //it return sqrt in [1,2,3,4]'s each item

  1. Array.prototype.each = function(fn){
  2. return this.length? [fn(this[0])].concat(this.slice(1).each(fn)): [];
  3. };
  4. //e.g.
  5. var arr = [1,2,3,4].each(function(x){return x*2;});
  6. //alert(arr);//[2,3,6,8]

Report this snippet  

You need to login to post a comment.