语法高亮,滚动条美化,设置页面调整

This commit is contained in:
fofolee
2019-04-19 02:41:09 +08:00
parent 1e8f76c000
commit 359d29ee0b
1590 changed files with 12328 additions and 11441 deletions

View File

@@ -1,9 +1,9 @@
<article id="wikiArticle">
<div></div>
<h2 id="错误信息">错误信息</h2>
<pre class="syntaxbox">TypeError: 'x' is not iterable (Firefox, Chrome)
<pre><code class="language-javascript">TypeError: 'x' is not iterable (Firefox, Chrome)
TypeError: 'x' is not a function or its return value is not iterable (Chrome)
</pre>
</code></pre>
<h2 id="错误类型">错误类型</h2>
<p><a href="Reference/Global_Objects/TypeError" title="TypeError类型错误 对象用来表示值的类型非预期类型时发生的错误。"><code>TypeError</code></a></p>
<h2 id="发生了什么错误">发生了什么错误?</h2>
@@ -11,13 +11,13 @@ TypeError: 'x' is not a function or its return value is not iterable (Chrome)
<h2 id="示例">示例</h2>
<h3 id="Iterating_over_Object_properties">Iterating over Object properties</h3>
<p>在JavaScript中, <a href="Reference/Global_Objects/Object" title="Object 构造函数创建一个对象包装器。"><code>Object</code></a> 是不可迭代的,除非它们实现了<a href="/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterable_protocol">迭代协议</a>. 因此, 你不能使用 <a href="/en-US/docs/Web/JavaScript/Guide/Loops_and_iteration#for...of_statement">for…of </a>来迭代对象的属性.</p>
<pre class="brush: js example-bad">var obj = { 'France': 'Paris', 'England': 'London' };
<pre><code class="language-js example-bad">var obj = { 'France': 'Paris', 'England': 'London' };
for (let p of obj) { // TypeError: obj is not iterable
// …
}
</pre>
</code></pre>
<p>做为替代你必须使用 <a href="Reference/Global_Objects/Object/keys" title="Object.keys() 方法会返回一个由一个给定对象的自身可枚举属性组成的数组,数组中属性名的排列顺序和使用 for...in 循环遍历该对象时返回的顺序一致 。"><code>Object.keys</code></a><a href="Reference/Global_Objects/Object/entries" 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.entries</code></a> 来迭代对象的属性或属性值.</p>
<pre class="brush: js example-good">var obj = { 'France': 'Paris', 'England': 'London' };
<pre><code class="language-js example-good">var obj = { 'France': 'Paris', 'England': 'London' };
// 迭代属性名称:
for (let country of obj.keys()) {
var capital = obj[country];
@@ -26,9 +26,9 @@ for (let country of obj.keys()) {
for (const [country, capital] of obj.entries())
console.log(country, capital);
</pre>
</code></pre>
<p>这次case的另外一个选择是使用 <a href="Reference/Map" title="此页面仍未被本地化, 期待您的翻译!"><code>Map</code></a>:</p>
<pre class="brush: js example-good">var map = new Map;
<pre><code class="language-js example-good">var map = new Map;
map.set('France', 'Paris');
map.set('England', 'London');
// Iterate over the property names:
@@ -42,26 +42,26 @@ for (let capital of map.values())
for (const [country, capital] of map.entries())
console.log(country, capital);
</pre>
</code></pre>
<h3 id="Iterating_over_a_generator">Iterating over a generator</h3>
<p><a href="/en-US/docs/Web/JavaScript/Guide/Iterators_and_Generators#Generators">Generators</a> 是用来生成可迭代对象的函数.</p>
<pre class="brush: js example-bad">function* generate(a, b) {
<pre><code class="language-js example-bad">function* generate(a, b) {
yield a;
yield b;
}
for (let x of generate) // TypeError: generate is not iterable
console.log(x);
</pre>
</code></pre>
<p>当它没有被调用, 这个 <a href="Reference/Function" title="此页面仍未被本地化, 期待您的翻译!"><code>Function</code></a> 相应的是可调用的,但是不可迭代。 调用 generator 生成一个可迭代对象,该对象将迭代在生成器执行期间生成的值.</p>
<pre class="brush: js example-good">function* generate(a, b) {
<pre><code class="language-js example-good">function* generate(a, b) {
yield a;
yield b;
}
for (let x of generate(1,2))
console.log(x);
</pre>
</code></pre>
<h2 id="参阅">参阅</h2>
<ul>
<li><a href="/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterable_protocol">iterable protocol</a></li>