es6 Reflect 与 Proxy
Posted essaycode
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了es6 Reflect 与 Proxy相关的知识,希望对你有一定的参考价值。
<script type="text/javascript"> let target = { name:"小明", age: 15 } let handler = { get(target, propKey, receive){ if(propKey in target){ console.log("success"); }else{ console.log("error") } return Reflect.get(target, propKey, receive); }, set(target, propKey, value, receiver){ if(propKey==‘age‘){ if(!Number.isInteger(value)){ throw new TypeError(‘The age is not an integer‘); }else{ console.log("set success"); } }else{ console.log("set success"); } return Reflect.set(target, propKey, value, receiver); }, has(target,proKey){ console.log(‘handle has‘); return proKey in target; } } let pro = new Proxy(target,handler); console.log(‘name‘ in pro) console.log(‘sex‘ in pro) /*pro.name=‘李四‘ pro.age=34 console.log(pro.name) console.log(pro.age)*/ </script>
以上是关于es6 Reflect 与 Proxy的主要内容,如果未能解决你的问题,请参考以下文章
@芥末的糖 ---------- ES6---Proxy与Reflect 实现重载(overload)