aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/javascript/reference/global_objects/object/isextensible
diff options
context:
space:
mode:
Diffstat (limited to 'files/zh-cn/web/javascript/reference/global_objects/object/isextensible')
-rw-r--r--files/zh-cn/web/javascript/reference/global_objects/object/isextensible/index.html144
1 files changed, 144 insertions, 0 deletions
diff --git a/files/zh-cn/web/javascript/reference/global_objects/object/isextensible/index.html b/files/zh-cn/web/javascript/reference/global_objects/object/isextensible/index.html
new file mode 100644
index 0000000000..c168d98bfd
--- /dev/null
+++ b/files/zh-cn/web/javascript/reference/global_objects/object/isextensible/index.html
@@ -0,0 +1,144 @@
+---
+title: Object.isExtensible()
+slug: Web/JavaScript/Reference/Global_Objects/Object/isExtensible
+translation_of: Web/JavaScript/Reference/Global_Objects/Object/isExtensible
+---
+<div>{{JSRef("Global_Objects", "Object")}}</div>
+
+<h2 id="Summary" name="Summary">概述</h2>
+
+<p><code><strong>Object.isExtensible()</strong></code> 方法判断一个对象是否是可扩展的(是否可以在它上面添加新的属性)。</p>
+
+<h2 id="Syntax" name="Syntax">语法</h2>
+
+<pre class="syntaxbox"><code>Object.isExtensible(<em>obj</em>)</code></pre>
+
+<h3 id="Parameters" name="Parameters">参数</h3>
+
+<dl>
+ <dt>obj</dt>
+ <dd>需要检测的对象</dd>
+</dl>
+
+<h3 id="返回值">返回值</h3>
+
+<p>    表示给定对象是否可扩展的一个<a href="https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Boolean" title="此页面仍未被本地化, 期待您的翻译!"><code>Boolean</code></a> 。</p>
+
+<h2 id="Description" name="Description">描述</h2>
+
+<p>默认情况下,对象是可扩展的:即可以为他们添加新的属性。以及它们的 {{jsxref("Object.proto", "__proto__")}}{{deprecated_inline}} 属性可以被更改。{{jsxref("Object.preventExtensions")}},{{jsxref("Object.seal")}} 或 {{jsxref("Object.freeze")}} 方法都可以标记一个对象为不可扩展(non-extensible)。</p>
+
+<h2 id="Examples" name="Examples">例子</h2>
+
+<pre class="brush: js">// 新对象默认是可扩展的.
+var empty = {};
+Object.isExtensible(empty); // === true
+
+// ...可以变的不可扩展.
+Object.preventExtensions(empty);
+Object.isExtensible(empty); // === false
+
+// 密封对象是不可扩展的.
+var sealed = Object.seal({});
+Object.isExtensible(sealed); // === false
+
+// 冻结对象也是不可扩展.
+var frozen = Object.freeze({});
+Object.isExtensible(frozen); // === false
+</pre>
+
+<p> </p>
+
+<h2 id="注意" style="margin-bottom: 20px; line-height: 30px;">注意</h2>
+
+<p>在 ES5 中,如果参数不是一个对象类型,将抛出一个 {{jsxref("TypeError")}} 异常。在 ES6 中, non-object 参数将被视为一个不可扩展的普通对象,因此会返回 false 。</p>
+
+<pre>Object.isExtensible(1);
+// TypeError: 1 is not an object (ES5 code)
+
+Object.isExtensible(1);
+// false (ES6 code)
+</pre>
+
+<h2 id="规范" style="margin-bottom: 20px; line-height: 30px;">规范</h2>
+
+<table class="standard-table">
+ <tbody>
+ <tr>
+ <th scope="col">Specification</th>
+ <th scope="col">Status</th>
+ <th scope="col">Comment</th>
+ </tr>
+ <tr>
+ <td>{{SpecName('ES5.1', '#sec-15.2.3.13', 'Object.isExtensible')}}</td>
+ <td>{{Spec2('ES5.1')}}</td>
+ <td>Initial definition.<br>
+ Implemented in JavaScript 1.8.5</td>
+ </tr>
+ <tr>
+ <td>{{SpecName('ES6', '#sec-object.isextensible', 'Object.isExtensible')}}</td>
+ <td>{{Spec2('ES6')}}</td>
+ <td> </td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="浏览器兼容性">浏览器兼容性</h2>
+
+<div>{{CompatibilityTable}}</div>
+
+<div id="compat-desktop">
+<table class="compat-table">
+ <tbody>
+ <tr>
+ <th>Feature</th>
+ <th>Firefox (Gecko)</th>
+ <th>Chrome</th>
+ <th>Internet Explorer</th>
+ <th>Opera</th>
+ <th>Safari</th>
+ </tr>
+ <tr>
+ <td>Basic support</td>
+ <td>4 (2.0)</td>
+ <td>6</td>
+ <td>9</td>
+ <td>12</td>
+ <td>5.1</td>
+ </tr>
+ </tbody>
+</table>
+</div>
+
+<div id="compat-mobile">
+<table class="compat-table">
+ <tbody>
+ <tr>
+ <th>Feature</th>
+ <th>Firefox Mobile (Gecko)</th>
+ <th>Android</th>
+ <th>IE Mobile</th>
+ <th>Opera Mobile</th>
+ <th>Safari Mobile</th>
+ </tr>
+ <tr>
+ <td>Basic support</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatUnknown}}</td>
+ </tr>
+ </tbody>
+</table>
+</div>
+
+<h2 id="See_also" name="See_also" style="margin-bottom: 20px; line-height: 30px;">相关链接</h2>
+
+<ul>
+ <li><strong>{{jsxref("Object.preventExtensions")}}</strong></li>
+ <li>{{jsxref("Object.seal")}}</li>
+ <li>{{jsxref("Object.isSealed")}}</li>
+ <li>{{jsxref("Object.freeze")}}</li>
+ <li>{{jsxref("Object.isFrozen")}}</li>
+</ul>