JavaScript ES6对Proxy的原生支持的一个例子:开发人员学习额外的编程语言

</div><div data-lake-id="44d14ca6b0db80cbbdebfe42382b6b18">function Employee(name){</div><div data-lake-id="c0028caa0ae93dcb06f61944cfd80a07"> this.name = name;</div><div data-lake-id="fc91c9b456c868155ee6801be1b3650a">};</div><div data-lake-id="69983cea3cb8ed7fb2ee3d1732959107">Employee.prototype.work = function(language){</div><div data-lake-id="c7467e9164ad7184a1f067c095b06ff8"> console.log(this.name + " is developing with: " + language);</div><div data-lake-id="275ee0cb200bf040fc1af3a3f56126d7">}</div><div data-lake-id="49b82ae9fca0d7b5399c37974656c2bb">let jerry = new Employee("Jerry");</div><div data-lake-id="f6e5ccf3afe37dbb225aff62565f01c2">function hireEmployee(employee, language){</div><div data-lake-id="8cf8743009a9aa01b94446615fcd41b0">    employee.work(language);</div><div data-lake-id="9fb3a31b5176f362dad7b10705a82d79">}</div><div data-lake-id="3e20b048502629ef8da2654d608dfdc8">hireEmployee(jerry, "JavaScript");</div><div data-lake-id="67473a5e39940d922fd3986fa222d4bf">var proxyLogic = {</div><div data-lake-id="725ecc5775e3246da29e8b8ff558c7d3">    get: function(target, name) {</div><div data-lake-id="e6cce5adf618f2516746a15b371d9e31">     if( name == "work"){</div><div data-lake-id="c8e49d360d1f4d338a584417419b94ff">      var oriFun = target[name].bind(target);</div><div data-lake-id="a95e672168ec9e606b001536b507c9d4">      return function(language){</div><div data-lake-id="c2982a1547f996752dbd96b207ac4b34">       oriFun(language);</div><div data-lake-id="d9a0980cb21ebd672c71f03d243afaab">       console.log("and also study other language in spare time");</div><div data-lake-id="f35c35310d82a7ae364c1bd5b552a6c1">      }</div><div data-lake-id="e8ee570e31dcd8574b05cfaac8b870eb">     }</div><div data-lake-id="301661cf067d17147ed4b9aa9a1aea0c">    }</div><div data-lake-id="4bc35c577e815ae49106cabef343dc51">};</div><div data-lake-id="6c818adfe8af9993ffc9666a87b61e56">var jerryProxy = new Proxy(jerry, proxyLogic );</div><div data-lake-id="2961c0b9a10a069a45354208dfca4485">hireEmployee(jerryProxy, "JavaScript");</div><div data-lake-id="2f46fc9349e85a7433b271a580e6a454">


JavaScript ES6对Proxy的原生支持的一个例子:开发人员学习额外的编程语言JavaScript ES6对Proxy的原生支持的一个例子:开发人员学习额外的编程语言

上一篇:MaxCompute计算长尾问题


下一篇:java 线程public void run()中值如何返回