【js-curray】
<h4>实现curray</h4>
<hr />
<h3>题目描述</h3>
<p>实现函数curry,该函数接受一个多元(多个参数)的函数作为参数,然后一个新的函数,这个函数 可以一次执行,也可以分多次执行。</p>
<pre><code>function curry(fn){
const ctx =this;
function inner(...args){
if(args.length === fn.length) return fn.call(ctx,...args);
return (...innerArgs) => inner.call(ctx,...args,...innerArgs)
}
return inner ;
}
// test
function test(a, b, c) {
console.log(a, b, c);
}
const f1 = curry(test)(1);
const f2 = f1(2);
f2(3);
</code></pre>