mirror of
https://github.com/fofolee/uTools-Manuals.git
synced 2025-06-09 23:44:06 +08:00
127 lines
8.2 KiB
HTML
127 lines
8.2 KiB
HTML
<article id="wikiArticle">
|
||
<div></div>
|
||
<h2 id="Summary" name="Summary">概述</h2>
|
||
<p><code><strong>Object.isExtensible()</strong></code> 方法判断一个对象是否是可扩展的(是否可以在它上面添加新的属性)。</p>
|
||
<h2 id="Syntax" name="Syntax">语法</h2>
|
||
<pre><code class="language-javascript"><code>Object.isExtensible(<em>obj</em>)</code></code></pre>
|
||
<h3 id="Parameters" name="Parameters">参数</h3>
|
||
<dl>
|
||
<dt>obj</dt>
|
||
<dd>需要检测的对象</dd>
|
||
</dl>
|
||
<h3 id="返回值">返回值</h3>
|
||
<p> 表示给定对象是否可扩展的一个<a href="https://developer.mozilla.orgReference/Boolean" title="此页面仍未被本地化, 期待您的翻译!"><code>Boolean</code></a> 。</p>
|
||
<h2 id="Description" name="Description">描述</h2>
|
||
<p>默认情况下,对象是可扩展的:即可以为他们添加新的属性。以及它们的 <a href="Reference/Global_Objects/Object/proto" title="使用__proto__是有争议的,也不鼓励使用它。因为它从来没有被包括在EcmaScript语言规范中,但是现代浏览器都实现了它。__proto__属性已在ECMAScript 6语言规范中标准化,用于确保Web浏览器的兼容性,因此它未来将被支持。它已被不推荐使用, 现在更推荐使用Object.getPrototypeOf/Reflect.getPrototypeOf 和Object.setPrototypeOf/Reflect.setPrototypeOf(尽管如此,设置对象的[[Prototype]]是一个缓慢的操作,如果性能是一个问题,应该避免)。"><code>__proto__</code></a><span title="This deprecated API should no longer be used, but will probably still work."><i class="icon-thumbs-down-alt"> </i></span> 属性可以被更改。<a href="Reference/Global_Objects/Object/preventExtensions" title="Object.preventExtensions()方法让一个对象变的不可扩展,也就是永远不能再添加新的属性。"><code>Object.preventExtensions</code></a>,<a href="Reference/Global_Objects/Object/seal" title="The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request."><code>Object.seal</code></a> 或 <a href="Reference/Global_Objects/Object/freeze" title="Object.freeze() 方法可以冻结一个对象。一个被冻结的对象再也不能被修改;冻结了一个对象则不能向这个对象添加新的属性,不能删除已有属性,不能修改该对象已有属性的可枚举性、可配置性、可写性,以及不能修改已有属性的值。此外,冻结一个对象后该对象的原型也不能被修改。freeze() 返回和传入的参数相同的对象。"><code>Object.freeze</code></a> 方法都可以标记一个对象为不可扩展(non-extensible)。</p>
|
||
<h2 id="Examples" name="Examples">例子</h2>
|
||
<pre><code class="language-javascript">// 新对象默认是可扩展的.
|
||
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
|
||
</code></pre>
|
||
<p> </p>
|
||
<h2 id="注意" style="margin-bottom: 20px; line-height: 30px;">注意</h2>
|
||
<p>在 ES5 中,如果参数不是一个对象类型,将抛出一个 <a href="Reference/Global_Objects/TypeError" title="TypeError(类型错误) 对象用来表示值的类型非预期类型时发生的错误。"><code>TypeError</code></a> 异常。在 ES6 中, non-object 参数将被视为一个不可扩展的普通对象,因此会返回 false 。</p>
|
||
<pre>Object.isExtensible(1);
|
||
// TypeError: 1 is not an object (ES5 code)
|
||
|
||
Object.isExtensible(1);
|
||
// false (ES6 code)
|
||
</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><a class="external" href="https://www.ecma-international.org/ecma-262/5.1/#sec-15.2.3.13" hreflang="en" lang="en" rel="noopener">ECMAScript 5.1 (ECMA-262)<br/><small lang="zh-CN">Object.isExtensible</small></a></td>
|
||
<td><span class="spec-Standard">Standard</span></td>
|
||
<td>Initial definition.<br/>
|
||
Implemented in JavaScript 1.8.5</td>
|
||
</tr>
|
||
<tr>
|
||
<td><a class="external" href="https://www.ecma-international.org/ecma-262/6.0/#sec-object.isextensible" hreflang="en" lang="en" rel="noopener">ECMAScript 2015 (6th Edition, ECMA-262)<br/><small lang="zh-CN">Object.isExtensible</small></a></td>
|
||
<td><span class="spec-Standard">Standard</span></td>
|
||
<td> </td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
<h2 id="浏览器兼容性">浏览器兼容性</h2>
|
||
<div><div class="blockIndicator warning"><strong><a class="external" href="https://github.com/mdn/browser-compat-data" rel="noopener">We're converting our compatibility data into a machine-readable JSON format</a></strong>.
|
||
This compatibility table still uses the old format,
|
||
because we haven't yet converted the data it contains.
|
||
<strong><a class="new" href="/zh-CN/docs/MDN/Contribute/Structures/Compatibility_tables" rel="nofollow">Find out how you can help!</a></strong></div>
|
||
<div class="htab">
|
||
<a id="AutoCompatibilityTable" name="AutoCompatibilityTable"></a>
|
||
<ul>
|
||
<li class="selected"><a>Desktop</a></li>
|
||
<li><a>Mobile</a></li>
|
||
</ul>
|
||
</div></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><span style="color: rgb(255, 153, 0);" title="Compatibility unknown; please update this.">?</span></td>
|
||
<td><span style="color: rgb(255, 153, 0);" title="Compatibility unknown; please update this.">?</span></td>
|
||
<td><span style="color: rgb(255, 153, 0);" title="Compatibility unknown; please update this.">?</span></td>
|
||
<td><span style="color: rgb(255, 153, 0);" title="Compatibility unknown; please update this.">?</span></td>
|
||
<td><span style="color: rgb(255, 153, 0);" title="Compatibility unknown; please update this.">?</span></td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
<h2 id="See_also" name="See_also" style="margin-bottom: 20px; line-height: 30px;">相关链接</h2>
|
||
<ul>
|
||
<li><strong><a href="Reference/Global_Objects/Object/preventExtensions" title="Object.preventExtensions()方法让一个对象变的不可扩展,也就是永远不能再添加新的属性。"><code>Object.preventExtensions</code></a></strong></li>
|
||
<li><a href="Reference/Global_Objects/Object/seal" title="The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request."><code>Object.seal</code></a></li>
|
||
<li><a href="Reference/Global_Objects/Object/isSealed" title="Object.isSealed() 方法判断一个对象是否被密封。"><code>Object.isSealed</code></a></li>
|
||
<li><a href="Reference/Global_Objects/Object/freeze" title="Object.freeze() 方法可以冻结一个对象。一个被冻结的对象再也不能被修改;冻结了一个对象则不能向这个对象添加新的属性,不能删除已有属性,不能修改该对象已有属性的可枚举性、可配置性、可写性,以及不能修改已有属性的值。此外,冻结一个对象后该对象的原型也不能被修改。freeze() 返回和传入的参数相同的对象。"><code>Object.freeze</code></a></li>
|
||
<li><a href="Reference/Global_Objects/Object/isFrozen" title="Object.isFrozen()方法判断一个对象是否被冻结。"><code>Object.isFrozen</code></a></li>
|
||
</ul>
|
||
</article> |