javascript柯里化

function curry(fn){
  var slice = Array.prototype.slice;
  var arr = slice.call(arguments,1);
  return function(){
    var newArr = slice.call(arguments);
    var args = newArr.concat(arr);
    return fn.apply(null,args);
  }
}
function add(){
  var icur = 0;
  for(var i=0; i <arguments.length; i++){
    icur += arguments[i],10;
  }
  return icur;
}
var number = curry(add,1)(2,3,4,5,6,7,8,9,10);
console.log(number); //55

你可能感兴趣的:(JavaScript)