# curry柯里化
function curry(fn, args) {
var length = fn.length;
args = args || [];
return function() {
var _args = args;
for (let i = 0; i < arguments.length; i++) {
_args.push(arguments[i]);
}
if (_args.length < length) {
return curry.call(this, fn, _args);
} else {
return fn.apply(this, args);
}
};
}
const fn = curry(function(a, b, c, d) {
console.log(a, b, c, d);
});
fn(1)(2)(4)(10);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
← currentCode debounce →