mirror of
https://github.com/fofolee/uTools-Manuals.git
synced 2026-02-27 17:44:35 +08:00
语法高亮,滚动条美化,设置页面调整
This commit is contained in:
@@ -8,9 +8,9 @@
|
||||
<div class="note"><code>for each...in</code> 是 <a class="external" href="http://www.ecma-international.org/publications/standards/Ecma-357.htm" rel="noopener" title="http://www.ecma-international.org/publications/standards/Ecma-357.htm">ECMA-357 (E4X)</a> 标准的一部分, 大部分非Mozilla浏览器都没有实现该标准, E4X并不是 ECMAScript 标准的一部分.</div>
|
||||
</div>
|
||||
<h2 id="Syntax" name="Syntax">语法</h2>
|
||||
<pre class="syntaxbox"><code>for each (<em>variable</em> in <em>object</em>) {
|
||||
<pre><code class="language-javascript"><code>for each (<em>variable</em> in <em>object</em>) {
|
||||
<em>statement</em>
|
||||
}</code></pre>
|
||||
}</code></code></pre>
|
||||
<h2 id="Parameters" name="Parameters">参数</h2>
|
||||
<dl>
|
||||
<dt><code>variable</code></dt>
|
||||
@@ -30,14 +30,14 @@
|
||||
<h3 id="Example:_Using_for_each...in" name="Example:_Using_for_each...in">例子: 使用<code>for each...in</code></h3>
|
||||
<p><strong>警告:</strong>永远不要使用for each...in语句遍历数组,仅用来遍历常规对象,<a href="/zh-CN/docs/JavaScript/Reference/Statements/for...in#Description" title="JavaScript/Reference/Statements/for...in#Description">这里讲解了为什么这么说</a>.</p>
|
||||
<p>下面的代码片段演示如何遍历一个对象的属性值, 并计算它们的和:</p>
|
||||
<pre class="brush:js">var sum = 0;
|
||||
<pre><code class="language-js">var sum = 0;
|
||||
var obj = {prop1: 5, prop2: 13, prop3: 8};
|
||||
|
||||
for each (var item in obj) {
|
||||
sum += item;
|
||||
}
|
||||
|
||||
print(sum); // 输出"26",也就是5+13+8的值</pre>
|
||||
print(sum); // 输出"26",也就是5+13+8的值</code></pre>
|
||||
<h2 id="See_also" name="See_also">参见</h2>
|
||||
<ul>
|
||||
<li><a href="/zh-CN/docs/JavaScript/Reference/Statements/for...in" title="JavaScript/Reference/Statements/for...in">for...in</a> - 一个相似的语法,用来遍历对象的属性名称而非属性值.</li>
|
||||
|
||||
Reference in New Issue
Block a user