基本的函数柯里化curry方法

function curry(fn) {
  var args = Array.prototype.slice.call(arguments, 1)
  return function() {
    var innerArgs = Array.prototype.slice.call(arguments)
    var finalArgs = args.concat(innerArgs)
    return fn.apply(null, finalArgs)
  }
}

var abc = function(a, b, c) {
  return [a, b, c]
}

var curried = curry(abc, 1)

curried(2, 3)
// => [1, 2, 3]

 

你可能感兴趣的:(lodash)