📜  JavaScript handler isExtensible()方法

📅  最后修改于: 2020-10-25 09:18:20             🧑  作者: Mango

JavaScript handler.isExtensible()方法

handler.isExtensible()方法是Object.isExtensible()的陷阱。我们通常可以用于记录或审核对Object.isExtensible的调用(确定对象是否“可扩展”)。

句法

isExtensible: function(target)

参量

target:目标对象。

返回值

返回一个布尔值。

浏览器支持

Chrome Compatibility unknown
Edge Compatibility unknown
Firefox 31
Opera Compatibility unknown

例子1

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

例子2

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 

例子3

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