const pipe = (function() {
return value=> {
const funcStack = []
const oproxy = new Proxy({}, {
get(pipeObject, fnName) {
if(fnName === 'get') {
return funcStack.reduce((val, fn)=> fn(val), value)
}
funcStack.push(window[fnName])
return oproxy
}
})
return oproxy
}
})()
var add5 = a => a+5
var pow = n => n * n
pipe(3).add5.pow.get // 64
网友评论