mirror of
https://github.com/fofolee/uTools-Manuals.git
synced 2025-12-16 07:51:52 +08:00
语法高亮,滚动条美化,设置页面调整
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
<article id="wikiArticle">
|
||||
<div></div>
|
||||
<h2 id="错误提示">错误提示</h2>
|
||||
<pre class="syntaxbox">TypeError: can't delete non-configurable array element (Firefox)
|
||||
<pre><code class="language-javascript">TypeError: can't delete non-configurable array element (Firefox)
|
||||
TypeError: Cannot delete property '2' of [object Array] (Chrome)
|
||||
</pre>
|
||||
</code></pre>
|
||||
<h2 id="错误类型">错误类型</h2>
|
||||
<p><a href="Reference/Global_Objects/TypeError" title="TypeError(类型错误) 对象用来表示值的类型非预期类型时发生的错误。"><code>TypeError</code></a></p>
|
||||
<h2 id="哪里出错了?">哪里出错了?</h2>
|
||||
@@ -13,37 +13,37 @@ TypeError: Cannot delete property '2' of [object Array] (Chrome)
|
||||
<h2 id="示例">示例</h2>
|
||||
<h3 id="通过_Object.defineProperty_创建的不可配置属性"><code><font face="x-locale-heading-primary, zillaslab, Palatino, Palatino Linotype, x-locale-heading-secondary, serif">通过 </font>Object.defineProperty 创建的不可配置属性</code></h3>
|
||||
<p>使用 <a href="Reference/Global_Objects/Object/defineProperty" title="Object.defineProperty() 方法会直接在一个对象上定义一个新属性,或者修改一个对象的现有属性, 并返回这个对象。"><code>Object.defineProperty()</code></a> 且在没有明确将属性设定为可配置的情况下,默认可以创建不可配置属性。</p>
|
||||
<pre class="brush: js example-bad">var arr = [];
|
||||
<pre><code class="language-js example-bad">var arr = [];
|
||||
Object.defineProperty(arr, 0, {value: 0});
|
||||
Object.defineProperty(arr, 1, {value: "1"});
|
||||
|
||||
arr.length = 1;
|
||||
// TypeError: can't delete non-configurable array element
|
||||
</pre>
|
||||
</code></pre>
|
||||
<p>如果想要缩短数组长度的话,需要将其中的元素设置为可配置的。</p>
|
||||
<pre class="brush: js example-good">var arr = [];
|
||||
<pre><code class="language-js example-good">var arr = [];
|
||||
Object.defineProperty(arr, 0, {value: 0, configurable: true});
|
||||
Object.defineProperty(arr, 1, {value: "1", configurable: true});
|
||||
|
||||
arr.length = 1;
|
||||
</pre>
|
||||
</code></pre>
|
||||
<h3 id="密封的数组"><code>密封的数组</code></h3>
|
||||
<p> <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> 函数会将数组中现存的所有元素标记为不可配置。</p>
|
||||
<pre class="brush: js example-bad">var arr = [1,2,3];
|
||||
<pre><code class="language-js example-bad">var arr = [1,2,3];
|
||||
Object.seal(arr);
|
||||
|
||||
arr.length = 1;
|
||||
// TypeError: can't delete non-configurable array element
|
||||
</pre>
|
||||
</code></pre>
|
||||
<p>(为了解决上述问题,)或者是移除 <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> 调用,或者将数组拷贝一份。在拷贝数组的情况下,缩短备份数组的长度并不会修改原始数组的长度。</p>
|
||||
<pre class="brush: js example-good">var arr = [1,2,3];
|
||||
<pre><code class="language-js example-good">var arr = [1,2,3];
|
||||
Object.seal(arr);
|
||||
|
||||
// Copy the initial array to shorten the copy
|
||||
var copy = Array.from(arr);
|
||||
copy.length = 1;
|
||||
// arr.length == 3
|
||||
</pre>
|
||||
</code></pre>
|
||||
<h2 id="相关内容">相关内容</h2>
|
||||
<ul>
|
||||
<li><a href="/en-US/docs/Web/JavaScript/Data_structures#Properties">[[Configurable]]</a></li>
|
||||
|
||||
Reference in New Issue
Block a user