标签:lob code 例子 bsp 错误 split ble join receive
var pipe=(function(){ var pipe; return function(value){ pipe=[]; return new Proxy({}, { get(target, fnName, receiver){ console.log(‘enter get, fnName ‘ + fnName.toString()) if(fnName == ‘get‘){ console.log(‘begin to calc the value‘); return pipe.reduce(function(val, fn){ return fn(val); }, value); } pipe.push(global[fnName]); console.log(pipe, pipe.length); console.log(target); //此处应该是要返回proxy对象,而不是原来的target对象 return receiver; } }); } }()); //此处是为了兼容node环境而做的修改 global["double"] = n =>n*2; global["pow"] = n =>n*n; global["reverseInt"] = n=>n.toString().split(‘‘).reverse().join(‘‘) | 0; console.log(pipe(3).double.pow.reverseInt.get)
《es6标准入门》chapter11中关于Proxy的一个错误例子的纠正
标签:lob code 例子 bsp 错误 split ble join receive
原文地址:http://www.cnblogs.com/strinkbug/p/6675962.html