1 const add = x => x + 1;
2 const multiply = (x, y) => x * y;
3 const multiplyAdd = composeFunctions(multiply, add);
4
5 function composeFunctions() {
6 var args = Array.prototype.slice.apply(arguments);
7 console.log('args',args)
8 return function() {
9 if (args.length == 1) {
10 console.log('args=1',this)
11 return args[0].apply(this, Array.prototype.slice.apply(arguments));
12
13 }
14 console.log('args!=1',args)
15 return composeFunctions(...args.slice(1))(args[0].apply(this, Array.prototype.slice.apply(arguments)));
16 }
17 }
18 console.log(multiplyAdd(3, 4));// 返回 13