[英]JS Proxy & destructuring assignment
As what i know js Proxies make possible to overload classic object getter with a function call.据我所知,js 代理可以通过函数调用重载经典对象 getter。
So that we can do things like that :这样我们就可以做这样的事情:
const value = myProxy.value;
All that calling in fact the value getter function inside Proxy.所有这些实际上都调用了 Proxy 中的 value getter 函数。
My question is ... is there a way to use the JS destructuring syntax with JS Proxies ?我的问题是……有没有办法在 JS 代理中使用 JS 解构语法?
So that we could do things like that :这样我们就可以做这样的事情:
const { value } = myProxy;
Based on my tests, the second way is not working.根据我的测试,第二种方法不起作用。
It is working with a necessary implemented getter.它正在使用一个必要的已实现的吸气剂。
const myProxy = new Proxy({}, { get: function(obj, prop) { return 42; } }), { value } = myProxy; console.log(myProxy.value); console.log(value);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.