ECMAScript 6 引入了代理对象,该对象可以创建为可撤销的。
如何检测代理是否已被撤销?
最佳答案
Proxy
构造函数仅接受目标和处理程序(当它们是对象且不是已撤销代理时)。来自 ProxyCreate ,
- If Type(target) is not Object, throw a TypeError exception.
- If target is a Proxy exotic object and the value of the [[ProxyHandler]] internal slot of target is null, throw a TypeError exception.
这允许您检查某个值是否是已撤销的代理:您只需 ensure that it's an object但使 Proxy
抛出。
这样的事情应该有效:
function isRevokedProxy(value) {
try {
new Proxy(value, value);
return false;
} catch(err) {
return Object(value) === value;
}
}
关于javascript - 检查代理对象是否被撤销,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39335909/