handler.isExtensible() 方法用于拦截对对象的Object.isExtensible()。
语法
var p = new Proxy(target, {
isExtensible: function(target) {
}
});
参数
下列参数将会被传递给 isExtensible方法。 this 绑定在 handler 对象上。
-
target - 目标对象。
返回值
isExtensible方法必须返回一个 Boolean值或可转换成Boolean的值。
描述
handler.isExtensible()用于拦截对对象的Object.isExtensible()。
拦截
该方法会拦截目标对象的以下操作:
约束
如果违背了以下的约束,proxy会抛出 TypeError:
Object.isExtensible(proxy)必须同Object.isExtensible(target)返回相同值。也就是必须返回true或者为true的值,返回false和为false的值都会报错。
示例
以下代码演示Object.isExtensible().
var p = new Proxy({}, {
isExtensible: function(target) {
console.log('called');
return true;//也可以return 1;等表示为true的值
}
});
console.log(Object.isExtensible(p)); // "called"
// true
以下代码演示违反约束的情况。
var p = new Proxy({}, {
isExtensible: function(target) {
return false;//return 0;return NaN等都会报错
}
});
Object.isExtensible(p); // TypeError is thrown
规范
| Specification | Status | Comment |
|---|---|---|
| ECMAScript 2015 (6th Edition, ECMA-262) [[IsExtensible]] |
Standard | Initial definition. |
| ECMAScript Latest Draft (ECMA-262) [[IsExtensible]] |
Draft |
浏览器兼容性
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out
https://github.com/mdn/browser-compat-data and send us a pull request.
Update compatibility data on GitHub
| Desktop | Mobile | Server | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
isExtensible |
Chrome Full support 49 | Edge Full support 12 | Firefox Full support 31 | IE No support No | Opera Full support 36 | Safari ? | WebView Android Full support 49 | Chrome Android Full support 49 | Firefox Android Full support 31 | Opera Android Full support 36 | Safari iOS ? | Samsung Internet Android Full support 5.0 | nodejs Full support 6.0.0 |
Legend
- Full support
- Full support
- No support
- No support
- Compatibility unknown
- Compatibility unknown