<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>curry</title>
</head>
<body>
<script>
function curry(fn) {
var _argLen = fn.length
function wrap() {
var _args = [].slice.call(arguments)
function act() {
_args = _args.concat([].slice.call(arguments))
if(_args.length === _argLen) {
return fn.apply(null, _args)
}
return arguments.callee
}
if(_args.length === _argLen) {
return fn.apply(null, _args)
}
act.toString = function() {
return fn.toString()
}
return act
}
return wrap
}
var abc = function(a, b, c) {
return [a, b, c]
}
var curried = curry(abc)
console.log(curried(1)(2)(3))
// => [1, 2, 3]
console.log(curried(1, 2, 3))
// => [1, 2, 3]
console.log(curried(1, 2)(3))
// => [1, 2, 3]
console.log(curried(1)(2, 3))
// => [1, 2, 3]
</script>
</body>
</html>