Reflect.isExtensible()
Reflect.isExtensible() 静态方法与 Object.isExtensible() 类似。它确定对象是否可扩展(是否可以添加新属性)。
¥The Reflect.isExtensible() static method is like Object.isExtensible(). It determines if an object is extensible (whether it can have new properties added to it).
Try it
语法
参数
返回值
例外情况
描述
¥Description
Reflect.isExtensible() 提供检查对象是否可扩展的反射语义。与 Object.isExtensible() 的唯一区别是非对象目标的处理方式。如果目标不是对象,则 Reflect.isExtensible() 抛出 TypeError,而对于非对象目标,Object.isExtensible() 始终返回 false。
¥Reflect.isExtensible() provides the reflective semantic of checking if an object is extensible. The only difference with Object.isExtensible() is how non-object targets are handled. Reflect.isExtensible() throws a TypeError if the target is not an object, while Object.isExtensible() always returns false for non-object targets.
Reflect.isExtensible() 调用 target 的 [[IsExtensible]] 对象内部方法。
¥Reflect.isExtensible() invokes the [[IsExtensible]] object internal method of target.
示例
使用 Reflect.isExtensible()
¥Using Reflect.isExtensible()
¥See also Object.isExtensible().
// New objects are extensible.
const empty = {};
Reflect.isExtensible(empty); // true
// ...but that can be changed.
Reflect.preventExtensions(empty);
Reflect.isExtensible(empty); // false
// Sealed objects are by definition non-extensible.
const sealed = Object.seal({});
Reflect.isExtensible(sealed); // false
// Frozen objects are also by definition non-extensible.
const frozen = Object.freeze({});
Reflect.isExtensible(frozen); // false
与 Object.isExtensible() 的区别
¥Difference with Object.isExtensible()
如果此方法的 target 参数不是对象(基元),那么它将导致 TypeError。对于 Object.isExtensible(),非对象 target 将返回 false,不会出现任何错误。
¥If the target argument to this method is not an object (a primitive), then it will cause a TypeError. With Object.isExtensible(), a non-object target will return false without any errors.
Reflect.isExtensible(1);
// TypeError: 1 is not an object
Object.isExtensible(1);
// false
规范
| Specification |
|---|
| ECMAScript Language Specification # sec-reflect.isextensible |
浏览器兼容性
BCD tables only load in the browser