console
let compose = (...args) => (val) => {
args.forEach( e=> val = e(val))
return val
}
let toUpperCase = (x) => x.toUpperCase();
let concatAnotherStr = (x) => x + '_by_nowell_';
let rever
let shout = compose(toUpperCase,exclaim ,(v)=> v+'___' ,(v)=> v+'@@');
v = shout('jsstr')
console.log(v)
let compose2 = (...args) => {
return args.reduce((a, b) => (arg) => a(b(arg)))
}
shout = compose2(toUpperCase,exclaim ,(v)=> v+'___', (v)=> v+'@@' );
v = shout('jsstr')
console.log(v)
<body>
<p>compose 聚合函数: 将多个函数串行执行,每个函数的结果将作为下个函数的参数</p>
<p>可以使用forEach或者reduce两种方式,redux的中间件则采用了reduce的方式实现</p>
</body>