--- title: Reflect.isExtensible() slug: Web/JavaScript/Reference/Global_Objects/Reflect/isExtensible translation_of: Web/JavaScript/Reference/Global_Objects/Reflect/isExtensible ---
静态方法 Reflect
.isExtensible()
判断一个对象是否可扩展 (即是否能够添加新的属性)。与它 {{jsxref("Object.isExtensible()")}} 方法相似,但有一些不同,详情可见 {{anch("Difference to Object.isExtensible()", "differences")}}。
Reflect.isExtensible(target)
target
返回一个 {{jsxref("Boolean")}} 值表明该对象是否可扩展。
抛出一个 {{jsxref("TypeError")}},如果对象不是 {{jsxref("Object")}}。
Reflect.isExtensible 判断
一个对象是否可扩展 (即是否能够添加新的属性)。它与 {{jsxref("Object.isExtensible()")}} 方法一样。
Reflect.isExtensible()
详情可见 {{jsxref("Object.isExtensible()")}}。
// New objects are extensible. var empty = {}; Reflect.isExtensible(empty); // === true // ...but that can be changed. Reflect.preventExtensions(empty); Reflect.isExtensible(empty); // === false // Sealed objects are by definition non-extensible. var sealed = Object.seal({}); Reflect.isExtensible(sealed); // === false // Frozen objects are also by definition non-extensible. var frozen = Object.freeze({}); Reflect.isExtensible(frozen); // === false
Object.isExtensible() 的不同点
如果该方法的第一个参数不是一个对象(原始值),那么将造成一个 {{jsxref("TypeError")}} 异常。对于 {{jsxref("Object.isExtensible()")}},非对象的第一个参数会被强制转换为一个对象。
Reflect.isExtensible(1); // TypeError: 1 is not an object Object.isExtensible(1); // false
Specification | Status | Comment |
---|---|---|
{{SpecName('ES6', '#sec-reflect.isextensible', 'Reflect.isExtensible')}} | {{Spec2('ES6')}} | Initial definition. |
{{SpecName('ESDraft', '#sec-reflect.isextensible', 'Reflect.isExtensible')}} | {{Spec2('ESDraft')}} |
{{CompatibilityTable}}
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Basic support | 49 | {{CompatGeckoDesktop(42)}} | {{CompatNo}} | {{CompatNo}} | 10 |
Feature | Android | Chrome for Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|
Basic support | {{CompatNo}} | 49 | {{CompatGeckoMobile(42)}} | {{CompatNo}} | {{CompatNo}} | 10 |