📅  最后修改于: 2020-10-25 09:18:20             🧑  作者: Mango
handler.isExtensible()方法是Object.isExtensible()的陷阱。我们通常可以用于记录或审核对Object.isExtensible的调用(确定对象是否“可扩展”)。
isExtensible: function(target)
target:目标对象。
返回一个布尔值。
Chrome | Compatibility unknown |
Edge | Compatibility unknown |
Firefox | 31 |
Opera | Compatibility unknown |
var x = { foo: 1 };
var proxy = new Proxy(x, {
isExtensible: function(target) {
document.writeln('in isExtensible');
//expected output: in isExtensible
return Object.isExtensible(target);
}
});
document.writeln(Object.isExtensible(proxy));
//expected output: true
document.writeln("
")
Object.preventExtensions(proxy);
document.writeln(Object.isExtensible(proxy));
//expected output: false
输出:
in isExtensible true
in isExtensible false
const pro={
too:1 }
const proxy = new Proxy(pro, {
isExtensible: function(target) {
document.writeln(' in value : ');
return true;
}
});
document.writeln(Object.isExtensible(proxy));
//expected output: in value : true
输出:
in value : true
var a = {
canEvolve: true
};
var b = {
isExtensible(target) {
return true;
},
};
const proxy1 = new Proxy(a, b);
document.writeln(Object.isExtensible(proxy1));
// expected output: true
输出:
true