``` js function compose(...fns) { const length = fns.length for (let i = 0; i < length; i++) { if (typeof fns[i] !== 'function') { throw new TypeError('Expected arguments are functions') } } return function (...args) { let index = 0 let result = length ? fns[index].apply(this, args) : args while (++index < length) { result = fns[index].call(this, result) } return result } } // test function double(num) { return num * 2 } function square(num) { return num ** 2 } const newFn = compose(double, square) console.log(newFn(10)) ```
Activity
ChenHaoJie9527 commentedon Jun 27, 2022
组合函数-简单版
luckept commentedon Jun 27, 2022
不知道理解得对不对
myltx commentedon Jun 29, 2022
这样的也可以达到效果