Proxy.handler.isExtensible
handler.isExtensible()用于拦截对对象的Object.isExtensible()。
语法
var p = new Proxy(target, {
isExtensible: function(target) {
}
});
参数
下列参数将会被传递给 isExtensible
方法。 this 绑定在 handler 对象上。
target
目标对象。
返回值
isExtensible
方法必须返回一个 Boolean值或可转换成Boolean的值。
描述
handler.isExtensible()用于拦截对对象的Object.isExtensible()。
拦截
该方法会拦截目标对象的以下操作:
Object.isExtensible()
Reflect.isExtensible()
约束
如果违背了以下的约束,proxy会抛出 TypeError:
Object.isExtensible(proxy)
必须返回与之相同的值Object.isExtensible(target)
。
示例
以下代码陷阱Object.isExtensible()
。
var p = new Proxy({}, {
isExtensible: function(target) {
console.log('called');
return true;
}
});
console.log(Object.isExtensible(p)); // "called"
// true
以下代码违反了不变量。
var p = new Proxy({}, {
isExtensible: function(target) {
return false;
}
});
Object.isExtensible(p); // TypeError is thrown
规范
规范 | 状态 | 评论 |
---|---|---|
ECMAScript 2015(第6版,ECMA-262)该规范中'[[IsExtensible]]'的定义。 | 标准 | 初始定义。 |
ECMAScript最新草案(ECMA-262)该规范中'[[IsExtensible]]'的定义。 | 草案 |
浏览器兼容性
Desktop | Mobile | Server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | Android webview | Chrome for Android | Edge Mobile | Firefox for Android | Opera for Android | iOS Safari | Samsung Internet | Node.js | |
基本支持 | ? | ? | 31 | 不支持 | ? | ? | ? | ? | ? | 31 | ? | ? | ? | ? |
另请参阅
本文档系腾讯云开发者社区成员共同维护,如有问题请联系 cloudcommunity@tencent.com