标签:logs ret reduce red 组合 add div2 pre 数组
const add1 = (x) => x + 1 const mul3 = (x) => x * 3 const div2 = (x) => x / 2 //每个函数都要return 进行传参数的 div2(mul3(add1(add1(0)))) // => 3 const compose = (...fns) => { return x => fns.reduceRight((v, f) => f(v), x); }
//调用
compose (add1,mul3,div2)
标签:logs ret reduce red 组合 add div2 pre 数组
原文地址:http://www.cnblogs.com/love314159/p/7656700.html