链式调用
//实现以下链式调用
//实现
var res1 = pipe(2).double.pow.do; //256
var res2 = pipe(4).add.double.do; //12
var res3 = pipe(6).sub.add.double.do //12
console.log(res1, res2, res3)
var pipe = function (value){
let fnTasks = []
return new Proxy({},{
get: function(target, property, receiver){
if(property === 'do'){
return fnTasks.reduce((prev, cur)=>{
return cur(prev)
}, value)
}else{
fnTasks.push(window[property])
return receiver
}
}
})
}
var add = n => n + 2
var sub = n => n - 2
var double = n => n * 2
var pow = n => Math.pow(n, n)