diff options
Diffstat (limited to 'files/zh-cn/web/javascript/reference/global_objects')
117 files changed, 375 insertions, 382 deletions
diff --git a/files/zh-cn/web/javascript/reference/global_objects/aggregateerror/index.html b/files/zh-cn/web/javascript/reference/global_objects/aggregateerror/index.html index ddc0486653..ff68e4fc49 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/aggregateerror/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/aggregateerror/index.html @@ -48,7 +48,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/AggregateError <h2 id="示例">示例</h2> -<h3 id="捕获一个AggregateError"><font face="x-locale-heading-primary, zillaslab, Palatino, Palatino Linotype, x-locale-heading-secondary, serif"><span style="background-color: #333333;">捕获一个</span></font>AggregateError</h3> +<h3 id="捕获一个AggregateError"><font face="x-locale-heading-primary, zillaslab, Palatino, Palatino Linotype, x-locale-heading-secondary, serif">捕获一个</font>AggregateError</h3> <pre class="brush: js; notranslate">Promise.any([ Promise.reject(new Error("some error")), @@ -85,7 +85,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/AggregateError </tr> <tr> <td><a href="https://tc39.es/proposal-promise-any/#sec-aggregate-error-constructor">ESNext Promise.any Proposal</a></td> - <td><span class="spec-Draft">Stage 3 Draft</span></td> + <td>Stage 3 Draft</td> <td>Initial definition.</td> </tr> </tbody> diff --git a/files/zh-cn/web/javascript/reference/global_objects/array/fill/index.html b/files/zh-cn/web/javascript/reference/global_objects/array/fill/index.html index 955cbc9d6a..6879a6b985 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/array/fill/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/array/fill/index.html @@ -36,13 +36,13 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Array/fill <h2 id="Description" name="Description">描述</h2> -<p><strong><code>fill</code></strong> 方法接受三个参数 <code>value</code>, <code>start</code> 以及 <code>end</code>.<span> <code>start</code> 和 <code>end</code> 参数是可选的, 其默认值分别为 <code>0</code> 和 <code>this</code> 对象的 <code>length </code></span>属性值。</p> +<p><strong><code>fill</code></strong> 方法接受三个参数 <code>value</code>, <code>start</code> 以及 <code>end</code>. <code>start</code> 和 <code>end</code> 参数是可选的, 其默认值分别为 <code>0</code> 和 <code>this</code> 对象的 <code>length </code>属性值。</p> -<p><span>如果 <code>start</code> 是个负数, 则开始索引会被自动计算成为 <code>length+start</code></span>, 其中<span> <code>length</code> 是 </span><code>this</code><span> 对象的 </span><code>length </code>属性值。<span>如果 </span><code>end</code><span> 是个负数, 则结束索引会被自动计算成为 </span><code>length+end</code>。</p> +<p>如果 <code>start</code> 是个负数, 则开始索引会被自动计算成为 <code>length+start</code>, 其中 <code>length</code> 是 <code>this</code> 对象的 <code>length </code>属性值。如果 <code>end</code> 是个负数, 则结束索引会被自动计算成为 <code>length+end</code>。</p> -<p><span><code><strong>fill</strong></code> 方法故意被设计成通用方法, 该方法不要求 <code>this</code> 是数组对象。</span></p> +<p><code><strong>fill</strong></code> 方法故意被设计成通用方法, 该方法不要求 <code>this</code> 是数组对象。</p> -<p><code><strong style="line-height: 1.5;">fill</strong></code><span style="line-height: 1.5;"> 方法是个可变方法, 它会改变调用它的 <code>this</code> 对象本身, 然后返回它, 而并不是返回一个副本。</span></p> +<p><code><strong style="line-height: 1.5;">fill</strong></code> 方法是个可变方法, 它会改变调用它的 <code>this</code> 对象本身, 然后返回它, 而并不是返回一个副本。</p> <p>当一个对象被传递给 <strong><code>fill</code></strong>方法的时候, 填充数组的是这个对象的引用。</p> diff --git a/files/zh-cn/web/javascript/reference/global_objects/array/findindex/index.html b/files/zh-cn/web/javascript/reference/global_objects/array/findindex/index.html index 9a58426f8d..7b1e3c7143 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/array/findindex/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/array/findindex/index.html @@ -37,7 +37,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Array/findIndex </dl> </dd> <dt><code>thisArg</code></dt> - <dd>可选。执行<code>callback</code>时作为<code style="font-size: 14px; line-height: inherit;">this</code>对象<span style="line-height: inherit;">的值.</span></dd> + <dd>可选。执行<code>callback</code>时作为<code style="font-size: 14px; line-height: inherit;">this</code>对象的值.</dd> </dl> <h3 id="返回值">返回值</h3> @@ -60,7 +60,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Array/findIndex <h3 id="Example_Testing_size_of_all_array_elements" name="Example:_Testing_size_of_all_array_elements">查找数组中首个质数元素的索引</h3> -<p><span style="line-height: inherit;">以下示例查找数组中素数的元素的索引(如果不存在素数,则返回-1)。</span></p> +<p>以下示例查找数组中素数的元素的索引(如果不存在素数,则返回-1)。</p> <pre class="brush: js notranslate">function isPrime(element, index, array) { var start = 2; diff --git a/files/zh-cn/web/javascript/reference/global_objects/array/flat/index.html b/files/zh-cn/web/javascript/reference/global_objects/array/flat/index.html index 5346c65b82..2f37e8f49b 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/array/flat/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/array/flat/index.html @@ -81,10 +81,10 @@ const flattened = arr => [].concat(...arr);</code></pre> <pre class="brush: js notranslate"><code>// 使用 reduce、concat 和递归展开无限多层嵌套的数组 var arr1 = [1,2,3,[1,2,3,4, [2,3,4]]]; </code> -<code class="language-js"><span class="keyword token">function</span> <span class="function token">flatDeep</span><span class="punctuation token">(</span><span class="parameter token">arr<span class="punctuation token">,</span> d <span class="operator token">=</span> <span class="number token">1</span></span><span class="punctuation token">)</span> <span class="punctuation token">{</span> - <span class="keyword token">return</span> d <span class="operator token">></span> <span class="number token">0</span> <span class="operator token">?</span> arr<span class="punctuation token">.</span><span class="function token">reduce</span><span class="punctuation token">(</span><span class="punctuation token">(</span><span class="parameter token">acc<span class="punctuation token">,</span> val</span><span class="punctuation token">)</span> <span class="operator token">=></span> acc<span class="punctuation token">.</span><span class="function token">concat</span><span class="punctuation token">(</span>Array<span class="punctuation token">.</span><span class="function token">isArray</span><span class="punctuation token">(</span>val<span class="punctuation token">)</span> <span class="operator token">?</span> <span class="function token">flatDeep</span><span class="punctuation token">(</span>val<span class="punctuation token">,</span> d <span class="operator token">-</span> <span class="number token">1</span><span class="punctuation token">)</span> <span class="punctuation token">:</span> val<span class="punctuation token">)</span><span class="punctuation token">,</span> <span class="punctuation token">[</span><span class="punctuation token">]</span><span class="punctuation token">)</span> - <span class="punctuation token">:</span> arr<span class="punctuation token">.</span><span class="function token">slice</span><span class="punctuation token">(</span><span class="punctuation token">)</span><span class="punctuation token">;</span> -<span class="punctuation token">}</span><span class="punctuation token">;</span></code> +<code class="language-js">function flatDeep(arr, d = 1) { + return d > 0 ? arr.reduce((acc, val) => acc.concat(Array.isArray(val) ? flatDeep(val, d - 1) : val), []) + : arr.slice(); +};</code> <code> flatDeep(arr1, Infinity); // [1, 2, 3, 1, 2, 3, 4, 2, 3, 4]</code></pre> diff --git a/files/zh-cn/web/javascript/reference/global_objects/array/flatmap/index.html b/files/zh-cn/web/javascript/reference/global_objects/array/flatmap/index.html index 001ea6c5a9..50c75a73ab 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/array/flatmap/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/array/flatmap/index.html @@ -54,13 +54,13 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Array/flatMap <h3 id="map_与_flatMap"><code>map()</code> 与 <code>flatMap()</code></h3> -<pre class="brush: js notranslate">var arr1 = <span class="js source"><span class="function-call js meta"><span class="js meta"><span class="brace js meta square"><span>[</span></span><span class="constant decimal js numeric"><span>1</span></span><span class="comma delimiter js meta object"><span>,</span></span><span> </span><span class="brace js meta square"><span>2, 3, 4]; +<pre class="brush: js notranslate">var arr1 = [1, 2, 3, 4]; -arr1.map(</span></span></span></span></span>x => [x * 2]<span class="js source"><span class="function-call js meta"><span class="js meta"><span class="brace js meta square"><span>);</span></span></span></span></span> +arr1.map(x => [x * 2]); // [[2], [4], [6], [8]] -arr1.flatMap(x => [x * 2]<span class="js source"><span class="function-call js meta"><span class="js meta"><span class="brace js meta square"><span>); -// [2, 4, 6, 8]</span></span></span></span></span> +arr1.flatMap(x => [x * 2]); +// [2, 4, 6, 8] // <code>only one level is flatt</code><code>ened</code> arr1.flatMap(x => [[x * 2]]); diff --git a/files/zh-cn/web/javascript/reference/global_objects/array/length/index.html b/files/zh-cn/web/javascript/reference/global_objects/array/length/index.html index 7b126495fb..8f17e9af1f 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/array/length/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/array/length/index.html @@ -82,25 +82,25 @@ function printEntries(arr) { <p>下面的例子中,通过数组下标遍历数组元素,并把每个元素的值修改为原值的2倍。</p> -<pre class="brush: js line-numbers language-js"><code class="language-js"><span class="keyword token">var</span> numbers <span class="operator token">=</span> <span class="punctuation token">[</span><span class="number token">1</span><span class="punctuation token">,</span> <span class="number token">2</span><span class="punctuation token">,</span> <span class="number token">3</span><span class="punctuation token">,</span> <span class="number token">4</span><span class="punctuation token">,</span> <span class="number token">5</span><span class="punctuation token">]</span><span class="punctuation token">;</span> -<span class="keyword token">var</span> length <span class="operator token">=</span> numbers<span class="punctuation token">.</span>length<span class="punctuation token">;</span> -<span class="keyword token">for</span> <span class="punctuation token">(</span><span class="keyword token">var</span> i <span class="operator token">=</span> <span class="number token">0</span><span class="punctuation token">;</span> i <span class="operator token"><</span> length<span class="punctuation token">;</span> i<span class="operator token">++</span><span class="punctuation token">)</span> <span class="punctuation token">{</span> - numbers<span class="punctuation token">[</span>i<span class="punctuation token">]</span> <span class="operator token">*</span><span class="operator token">=</span> <span class="number token">2</span><span class="punctuation token">;</span> -<span class="punctuation token">}</span> -<span class="comment token">// 遍历后的结果 [2, 4, 6, 8, 10]</span></code></pre> +<pre class="brush: js line-numbers language-js"><code class="language-js">var numbers = [1, 2, 3, 4, 5]; +var length = numbers.length; +for (var i = 0; i < length; i++) { + numbers[i] *= 2; +} +// 遍历后的结果 [2, 4, 6, 8, 10]</code></pre> <h3 id="Example:_Shortening_an_array" name="Example:_Shortening_an_array">截断数组</h3> <p>下面的例子中,如果数组长度大于 3,则把该数组的长度截断为 3 。</p> -<pre class="brush: js line-numbers language-js"><code class="language-js"><span class="keyword token">var</span> numbers <span class="operator token">=</span> <span class="punctuation token">[</span><span class="number token">1</span><span class="punctuation token">,</span> <span class="number token">2</span><span class="punctuation token">,</span> <span class="number token">3</span><span class="punctuation token">,</span> <span class="number token">4</span><span class="punctuation token">,</span> <span class="number token">5</span><span class="punctuation token">]</span><span class="punctuation token">;</span> +<pre class="brush: js line-numbers language-js"><code class="language-js">var numbers = [1, 2, 3, 4, 5]; -<span class="keyword token">if</span> <span class="punctuation token">(</span>numbers<span class="punctuation token">.</span>length <span class="operator token">></span> <span class="number token">3</span><span class="punctuation token">)</span> <span class="punctuation token">{</span> - numbers<span class="punctuation token">.</span>length <span class="operator token">=</span> <span class="number token">3</span><span class="punctuation token">;</span> -<span class="punctuation token">}</span> +if (numbers.length > 3) { + numbers.length = 3; +} -console<span class="punctuation token">.</span><span class="function token">log</span><span class="punctuation token">(</span>numbers<span class="punctuation token">)</span><span class="punctuation token">;</span> <span class="comment token">// [1, 2, 3]</span> -console<span class="punctuation token">.</span><span class="function token">log</span><span class="punctuation token">(</span>numbers<span class="punctuation token">.</span>length<span class="punctuation token">)</span><span class="punctuation token">;</span> <span class="comment token">// 3</span></code></pre> +console.log(numbers); // [1, 2, 3] +console.log(numbers.length); // 3</code></pre> <h2 id="规范">规范</h2> diff --git a/files/zh-cn/web/javascript/reference/global_objects/array/of/index.html b/files/zh-cn/web/javascript/reference/global_objects/array/of/index.html index 4636c06bdb..25e4a88a23 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/array/of/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/array/of/index.html @@ -45,8 +45,8 @@ Array(1, 2, 3); // [1, 2, 3] <h2 id="示例">示例</h2> -<pre class="brush: js" style="font-size: 14px;"><span style="line-height: 22px;">Array.of(1); // [1] -</span><span style="line-height: 22px;">Array.of(1, 2, 3); // [1, 2, 3]</span> +<pre class="brush: js" style="font-size: 14px;">Array.of(1); // [1] +Array.of(1, 2, 3); // [1, 2, 3] Array.of(undefined); // [undefined] </pre> diff --git a/files/zh-cn/web/javascript/reference/global_objects/array/reduce/index.html b/files/zh-cn/web/javascript/reference/global_objects/array/reduce/index.html index 75edc90a73..f356bceaf6 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/array/reduce/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/array/reduce/index.html @@ -79,7 +79,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Array/Reduce <li><code>array 数组</code></li> </ul> -<p>回调函数第一次执行时,<code>accumulator</code><span style="line-height: 1.5;"> 和</span><code>currentValue</code>的取值有两种情况:如果调用<code>reduce()</code>时提供了<code>initialValue</code>,<code>accumulator</code>取值为<code>initialValue</code>,<code>currentValue</code>取数组中的第一个值;如果没有提供 <code>initialValue</code>,那么<code>accumulator</code>取数组中的第一个值,<code>currentValue</code>取数组中的第二个值。</p> +<p>回调函数第一次执行时,<code>accumulator</code> 和<code>currentValue</code>的取值有两种情况:如果调用<code>reduce()</code>时提供了<code>initialValue</code>,<code>accumulator</code>取值为<code>initialValue</code>,<code>currentValue</code>取数组中的第一个值;如果没有提供 <code>initialValue</code>,那么<code>accumulator</code>取数组中的第一个值,<code>currentValue</code>取数组中的第二个值。</p> <div class="note"> <p><strong>注意:</strong>如果没有提供<code>initialValue</code>,reduce 会从索引1的地方开始执行 callback 方法,跳过第一个索引。如果提供<code>initialValue</code>,从索引0开始。</p> diff --git a/files/zh-cn/web/javascript/reference/global_objects/array/reduceright/index.html b/files/zh-cn/web/javascript/reference/global_objects/array/reduceright/index.html index e4846dbfbf..94ef4c7602 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/array/reduceright/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/array/reduceright/index.html @@ -29,9 +29,9 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Array/ReduceRight <dd>一个回调函数,用于操作数组中的每个元素,它可接受四个参数: <dl> <dt><code>accumulator</code></dt> - <dd><span class="tlid-translation translation" lang="zh-CN"><span title="">累加器:</span></span>上一次调用回调函数时,回调函数返回的值。首次调用回调函数时,如果 <code>initialValue</code> 存在,<span class="tlid-translation translation" lang="zh-CN"><span title="">累加器</span></span>即为 <code>initialValue</code>,否则须为数组中的最后一个元素(详见下方 <code>initialValue</code> 处相关说明)。</dd> + <dd>累加器:上一次调用回调函数时,回调函数返回的值。首次调用回调函数时,如果 <code>initialValue</code> 存在,累加器即为 <code>initialValue</code>,否则须为数组中的最后一个元素(详见下方 <code>initialValue</code> 处相关说明)。</dd> <dt><code>currentValue</code></dt> - <dd><span class="tlid-translation translation" lang="zh-CN"><span title="">当前元素:</span></span>当前被处理的元素。</dd> + <dd>当前元素:当前被处理的元素。</dd> <dt><code>index</code>{{optional_inline}}</dt> <dd>数组中当前被处理的元素的索引。</dd> <dt><code>array</code>{{optional_inline}}</dt> @@ -39,7 +39,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Array/ReduceRight </dl> </dd> <dt><code>initialValue</code>{{optional_inline}} </dt> - <dd><span class="tlid-translation translation" lang="zh-CN"><span title="">首次调用</span></span> <code>callback</code> 函数时,<span class="tlid-translation translation" lang="zh-CN"><span title="">累加器 </span></span> <code>accumulator</code> <span class="tlid-translation translation" lang="zh-CN"><span title="">的值</span></span>。如果未提供该初始值,则将使用数组中的最后一个元素,并跳过该元素。如果不给出初始值,则需保证数组不为空。<br> + <dd>首次调用 <code>callback</code> 函数时,累加器 <code>accumulator</code> 的值。如果未提供该初始值,则将使用数组中的最后一个元素,并跳过该元素。如果不给出初始值,则需保证数组不为空。<br> 否则,在空数组上调用 <code>reduce</code> 或 <code>reduceRight</code> 且未提供初始值(例如 <code>[].reduce( (acc, cur, idx, arr) => {} )</code> )的话,会导致类型错误 <code><a href="/zh-CN/docs/Web/JavaScript/Reference/Errors/Reduce_of_empty_array_with_no_initial_value">TypeError: reduce of empty array with no initial value</a></code>。</dd> <dt> <h3 id="返回值">返回值</h3> diff --git a/files/zh-cn/web/javascript/reference/global_objects/array/some/index.html b/files/zh-cn/web/javascript/reference/global_objects/array/some/index.html index 426e6b16a6..c6e408edd2 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/array/some/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/array/some/index.html @@ -50,7 +50,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Array/some <p><code>some()</code> 为数组中的每一个元素执行一次 <code>callback</code> 函数,直到找到一个使得 callback 返回一个“真值”(即可转换为布尔值 true 的值)。如果找到了这样一个值,<code>some()</code> 将会立即返回 <code>true</code>。否则,<code>some()</code> 返回 <code>false</code>。<code>callback</code> 只会在那些”有值“的索引上被调用,不会在那些被删除或从来未被赋值的索引上调用。</p> -<p><code style="font-style: normal; line-height: 1.5;">callback</code><span style="line-height: 1.5;"> 被调用时传入三个参数:元素的值,元素的索引,被遍历的数组。</span></p> +<p><code style="font-style: normal; line-height: 1.5;">callback</code> 被调用时传入三个参数:元素的值,元素的索引,被遍历的数组。</p> <p>如果一个<code>thisArg</code>参数提供给some(),它将被用作调用的 <code>callback</code>的 <code>this</code> 值。否则, 它的 <code>this</code> value将是 <code>undefined</code>。<code>this</code>的值最终通过callback来观察,根据 <a href="/en-US/docs/Web/JavaScript/Reference/Operators/this">the usual rules for determining the <code>this</code> seen by a function</a>的this判定规则来确定。</p> diff --git a/files/zh-cn/web/javascript/reference/global_objects/array/tostring/index.html b/files/zh-cn/web/javascript/reference/global_objects/array/tostring/index.html index 9d49798a94..2378e078f8 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/array/tostring/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/array/tostring/index.html @@ -30,7 +30,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Array/toString <h3 id="ECMAScript_5_semantics">ECMAScript 5 semantics</h3> -<p>从 JavaScript 1.8.5 (<span class="st">Firefox 4</span>) 开始,和 ECMAScript 第5版语义(semantics)一致,<code>toString()</code> 方法是通用的,可被用于任何对象。将调用{{jsxref("Object.prototype.toString()")}},并返回结果值。</p> +<p>从 JavaScript 1.8.5 (Firefox 4) 开始,和 ECMAScript 第5版语义(semantics)一致,<code>toString()</code> 方法是通用的,可被用于任何对象。将调用{{jsxref("Object.prototype.toString()")}},并返回结果值。</p> <h2 id="规范">规范</h2> diff --git a/files/zh-cn/web/javascript/reference/global_objects/array/unshift/index.html b/files/zh-cn/web/javascript/reference/global_objects/array/unshift/index.html index bac11d8233..b05c74e64f 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/array/unshift/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/array/unshift/index.html @@ -40,7 +40,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Array/unshift <p><code>unshift</code> 方法会在调用它的类数组对象的开始位置插入给定的参数。</p> -<p><code>unshift</code> 特意被设计成具有通用性;这个方法能够通过 {{jsxref("Function.call", "call")}} 或 {{jsxref("Function.apply", "apply")}} 方法作用于类数组对象上。<span style="line-height: inherit;">不过对于没有 length 属性(代表从0开始的一系列连续的数字属性的最后一个)的对象,调用该方法可能没有任何意义。</span></p> +<p><code>unshift</code> 特意被设计成具有通用性;这个方法能够通过 {{jsxref("Function.call", "call")}} 或 {{jsxref("Function.apply", "apply")}} 方法作用于类数组对象上。不过对于没有 length 属性(代表从0开始的一系列连续的数字属性的最后一个)的对象,调用该方法可能没有任何意义。</p> <p>注意, 如果传入多个参数,它们会被以块的形式插入到对象的开始位置,它们的顺序和被作为参数传入时的顺序一致。 于是,传入多个参数调用一次 <code>unshift</code> ,和传入一个参数调用多次 <code>unshift</code> (例如,循环调用),它们将得到不同的结果。例如:</p> diff --git a/files/zh-cn/web/javascript/reference/global_objects/arraybuffer/index.html b/files/zh-cn/web/javascript/reference/global_objects/arraybuffer/index.html index a136334b41..a7d35e161b 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/arraybuffer/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/arraybuffer/index.html @@ -40,7 +40,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/ArrayBuffer <h3 id="异常">异常</h3> -<p>如果 <font face="consolas, Liberation Mono, courier, monospace"><span style="background-color: rgba(220, 220, 220, 0.5);">length</span></font> 大于 {{jsxref("Number.MAX_SAFE_INTEGER")}}(>= 2 ** 53)或为负数,则抛出一个 {{jsxref("RangeError")}} 异常。</p> +<p>如果 <font face="consolas, Liberation Mono, courier, monospace">length</font> 大于 {{jsxref("Number.MAX_SAFE_INTEGER")}}(>= 2 ** 53)或为负数,则抛出一个 {{jsxref("RangeError")}} 异常。</p> <h2 id="描述">描述</h2> diff --git a/files/zh-cn/web/javascript/reference/global_objects/atomics/index.html b/files/zh-cn/web/javascript/reference/global_objects/atomics/index.html index adc026a104..838b6d8b99 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/atomics/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/atomics/index.html @@ -24,7 +24,6 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Atomics <h2 id="方法">方法</h2> <dl> - <dt><span class="hidden"> </span></dt> <dt>{{jsxref("Atomics.add()")}}</dt> <dd>将指定位置上的数组元素与给定的值相加,并返回相加前该元素的值。</dd> <dt><strong>{{jsxref("Atomics.and()")}}</strong></dt> diff --git a/files/zh-cn/web/javascript/reference/global_objects/atomics/load/index.html b/files/zh-cn/web/javascript/reference/global_objects/atomics/load/index.html index c3d37d1dcb..6e6ca0c1e9 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/atomics/load/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/atomics/load/index.html @@ -22,7 +22,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Atomics/load <dt><code>typedArray</code></dt> <dd>一个共享的整型数组。可以是 {{jsxref("Int8Array")}},{{jsxref("Uint8Array")}},{{jsxref("Int16Array")}},{{jsxref("Uint16Array")}},{{jsxref("Int32Array")}} 或 {{jsxref("Uint32Array")}}.</dd> <dt><code>index</code></dt> - <dd>在 <code>typedArray</code> 中需要加载的位置<font face="consolas, Liberation Mono, courier, monospace"><span style="background-color: rgba(220, 220, 220, 0.5);">。</span></font></dd> + <dd>在 <code>typedArray</code> 中需要加载的位置<font face="consolas, Liberation Mono, courier, monospace">。</font></dd> </dl> <h3 id="返回值">返回值</h3> diff --git a/files/zh-cn/web/javascript/reference/global_objects/bigint64array/index.html b/files/zh-cn/web/javascript/reference/global_objects/bigint64array/index.html index 31ac75a13e..69b980e18b 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/bigint64array/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/bigint64array/index.html @@ -39,13 +39,8 @@ translation_of: Web/JavaScript/Reference/Global_Objects/BigInt64Array <dt>{{jsxref("TypedArray.prototype.byteOffset", "BigInt64Array.prototype.byteOffset")}}</dt> <dd>返回 <code>BigInt64Array</code> 从{jsxref(“ArrayBuffer”)}}开始的偏移量(以字节为单位)。这在构造时已被固定的,因此是只读。</dd> <dt>{{jsxref("TypedArray.prototype.length", "BigInt64Array.prototype.length")}}</dt> - <dd><span class="hidden"> </span><span class="hidden"> </span><span class="hidden"> </span><span class="hidden"> </span><span class="hidden"> </span><span class="hidden"> </span><span class="hidden"> </span><span class="hidden"> </span><span class="hidden"> </span><span class="hidden"> </span><span class="hidden"> </span><span class="hidden"> </span><span class="hidden"> </span><span class="hidden"> </span><span class="hidden"> </span><span class="hidden"> </span> - <p>返回 <code>BigInt64Array</code> 中被<span class="hidden"> </span>保留的元<span class="hidden"> </span>素个数。这<span class="hidden"> </span><span class="hidden"> </span>在构造时是固定的,因此是只读<span class="hidden"> </span>。<span class="hidden"> </span><span class="hidden"> </span><strong><span class="hidden"> </span></strong></p> - - <p><span class="hidden"> </span><span class="hidden"> </span></p> - <span class="hidden"> </span><span class="hidden"> </span><span class="hidden"> </span><span class="hidden"> </span><span class="hidden"> </span><span class="hidden"> </span><span class="hidden"> </span><span class="hidden"> </span><span class="hidden"> </span><span class="hidden"> </span><span class="hidden"> </span><span class="hidden"> </span><span class="hidden"> </span><span class="hidden"> </span><span class="hidden"> </span><span class="hidden"> </span> - - <h2 id="sect1"><span class="hidden"> </span><span class="hidden"> </span><span class="hidden"> </span></h2> + <dd> + <p>返回 <code>BigInt64Array</code> 中被 保留的元 素个数。这 在构造时是固定的,因此是只读 。 <strong> </strong></p> </dd> </dl> diff --git a/files/zh-cn/web/javascript/reference/global_objects/boolean/tosource/index.html b/files/zh-cn/web/javascript/reference/global_objects/boolean/tosource/index.html index 2086ce07c6..a9f2272d3f 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/boolean/tosource/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/boolean/tosource/index.html @@ -10,7 +10,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Boolean/toSource --- <div>{{JSRef}} {{non-standard_header}}</div> -<p><span class="short_text" id="result_box" lang="zh-CN"><span>toSource()方法返回一个表示对象的源码的字符串。</span></span></p> +<p>toSource()方法返回一个表示对象的源码的字符串。</p> <h2 id="语法">语法</h2> @@ -19,28 +19,28 @@ Boolean.toSource()</pre> <h3 id="返回值">返回值</h3> -<p><span class="short_text" id="result_box" lang="zh-CN"><span>表示对象的源码的字符串。</span></span></p> +<p>表示对象的源码的字符串。</p> <h2 id="描述">描述</h2> -<p><span class="short_text" id="result_box" lang="zh-CN"><span>toSource方法返回以下值:</span></span></p> +<p>toSource方法返回以下值:</p> <ul> - <li><span id="result_box" lang="zh-CN"><span>对于内置的</span></span> {{jsxref("Boolean")}} <span lang="zh-CN"><span>对象,toSource返回以下字符串,表示源代码不可用:</span></span> + <li>对于内置的 {{jsxref("Boolean")}} 对象,toSource返回以下字符串,表示源代码不可用: <pre class="brush: js">function Boolean() { [native code] } </pre> </li> - <li><span class="short_text" id="result_box" lang="zh-CN"><span>对于</span></span> {{jsxref("Boolean")}}<span class="short_text" lang="zh-CN"><span> 的实例,toSource返回一个表示源代码的字符串。</span></span></li> + <li>对于 {{jsxref("Boolean")}} 的实例,toSource返回一个表示源代码的字符串。</li> </ul> -<p><span class="short_text" id="result_box" lang="zh-CN"><span>此方法通常由JavaScript在内部调用,而不是在代码中显式调用。</span></span></p> +<p>此方法通常由JavaScript在内部调用,而不是在代码中显式调用。</p> -<h2 id="规范"><span class="short_text" id="result_box" lang="zh-CN"><span>规范</span></span></h2> +<h2 id="规范">规范</h2> -<p><span id="result_box" lang="zh-CN"><span>不是任何标准的一部分。</span> <span>在JavaScript 1.3中实现。</span></span></p> +<p>不是任何标准的一部分。 在JavaScript 1.3中实现。</p> <h2 id="浏览器兼容性">浏览器兼容性</h2> diff --git a/files/zh-cn/web/javascript/reference/global_objects/dataview/setbigint64/index.html b/files/zh-cn/web/javascript/reference/global_objects/dataview/setbigint64/index.html index 5e9b6596d4..e97765e4be 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/dataview/setbigint64/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/dataview/setbigint64/index.html @@ -26,7 +26,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/DataView/setBigInt64 <dd>字节偏移量,为从视图的起始位置到数据存储位置的字节字节偏移量。</dd> <dt></dt> <dt>value</dt> - <dd><span class="blob-code-inner blob-code-marker">作为一个</span>{{jsxref("BigInt")}}类型设置的数值。满足一个带符号的64位整数的最大可能数值是 <code><span class="blob-code-inner blob-code-marker">2n ** (64n -1n) - 1n</span></code><span class="blob-code-inner blob-code-marker"> (<code>9223372036854775807n</code>)。当发生溢出时,将会变成负数(</span><code>-9223372036854775808n</code><span class="blob-code-inner blob-code-marker">)。</span></dd> + <dd>作为一个{{jsxref("BigInt")}}类型设置的数值。满足一个带符号的64位整数的最大可能数值是 <code>2n ** (64n -1n) - 1n</code> (<code>9223372036854775807n</code>)。当发生溢出时,将会变成负数(<code>-9223372036854775808n</code>)。</dd> <dt>littleEndian</dt> <dd>{{optional_inline}} 为可选参数,表示这个64位整数是否以{{Glossary("Endianness", "little-endian 或者big-endian")}}格式存储。如果设置为<code>false</code> 或者未指定(<code>undefined</code>),将会写入一个big-endian(大端模式:高位字节排放在内存的低地址端,低位字节排放在内存的高地址端)格式的数值。</dd> </dl> diff --git a/files/zh-cn/web/javascript/reference/global_objects/dataview/setbiguint64/index.html b/files/zh-cn/web/javascript/reference/global_objects/dataview/setbiguint64/index.html index bd2bfef8f4..264f83b51f 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/dataview/setbiguint64/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/dataview/setbiguint64/index.html @@ -25,7 +25,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/DataView/setBigUint64 <dt>byteOffset</dt> <dd>字节偏移量,为从视图的起始位置到数据存储位置的字节字节偏移量。</dd> <dt>value</dt> - <dd>作为一个BigInt类型设置的数值。满足一个无符号的64位整数的最大可能数值是 <code><span class="blob-code-inner blob-code-marker">2n ** 64n - 1n</span></code><span class="blob-code-inner blob-code-marker"> (</span><code>18446744073709551615n</code><span class="blob-code-inner blob-code-marker">)</span>。当发生溢出时,将会变成0。</dd> + <dd>作为一个BigInt类型设置的数值。满足一个无符号的64位整数的最大可能数值是 <code>2n ** 64n - 1n</code> (<code>18446744073709551615n</code>)。当发生溢出时,将会变成0。</dd> <dt>littleEndian</dt> <dd>为可选参数,表示这个64位整数是否以little-endian 或者big-endian格式存储。如果设置为false 或者未指定(undefined),将会写入一个big-endian(大端模式:高位字节排放在内存的低地址端,低位字节排放在内存的高地址端)格式的数值。</dd> </dl> diff --git a/files/zh-cn/web/javascript/reference/global_objects/date/date/index.html b/files/zh-cn/web/javascript/reference/global_objects/date/date/index.html index 2b1e77c4b3..f97d377482 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/date/date/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/date/date/index.html @@ -5,7 +5,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Date/Date --- <div>{{JSRef}}</div> -<p><span class="seoSummary">Creates a JavaScript <strong><code>Date</code></strong> instance that represents a single moment in time in a platform-independent format.</span> <code>Date</code> objects contain a <code>Number</code> that represents milliseconds since 1 January 1970 UTC.</p> +<p>Creates a JavaScript <strong><code>Date</code></strong> instance that represents a single moment in time in a platform-independent format. <code>Date</code> objects contain a <code>Number</code> that represents milliseconds since 1 January 1970 UTC.</p> <div>{{EmbedInteractiveExample("pages/js/date-constructor.html")}}</div> diff --git a/files/zh-cn/web/javascript/reference/global_objects/date/getdate/index.html b/files/zh-cn/web/javascript/reference/global_objects/date/getdate/index.html index 17608a744f..4bbfc8ad23 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/date/getdate/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/date/getdate/index.html @@ -27,12 +27,12 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Date/getDate <h3 id="Example:_Using_getDate" name="Example:_Using_getDate">例子: 使用getDate()<code>方法</code></h3> -<p>下面第二条语句将值25赋给 day 变量,该值<span style="line-height: 1.5;">基于日期对象 </span><code style="font-style: normal; line-height: 1.5;">Xmax95</code><span style="line-height: 1.5;">的值。</span></p> +<p>下面第二条语句将值25赋给 day 变量,该值基于日期对象 <code style="font-style: normal; line-height: 1.5;">Xmax95</code>的值。</p> -<pre class="brush:js language-js" style="padding: 1em 0px 1em 30px; border-left-width: 6px; border-left-style: solid; font-family: Consolas, Monaco, 'Andale Mono', monospace; font-size: 14px; text-shadow: none; direction: ltr; white-space: normal; background-color: rgba(234, 239, 242, 0.247059);"><code class="language-js" style="font-family: Consolas, Monaco, 'Andale Mono', monospace; color: inherit; text-shadow: none; direction: ltr; white-space: pre;"><span class="keyword token" style="color: #0077aa;">var</span> Xmas95 <span class="operator token" style="background: rgba(255, 255, 255, 0.498039); color: #a67f59;">=</span> <span class="keyword token" style="color: #0077aa;">new</span> <span class="class-name token">Date</span><span class="punctuation token" style="color: #999999;">(</span><span class="string token" style="color: #669900;">"December 25, 1995 23:15:00"</span><span class="punctuation token" style="color: #999999;">)</span><span class="punctuation token" style="color: #999999;">;</span> -<span class="keyword token" style="color: #0077aa;">var</span> day <span class="operator token" style="background: rgba(255, 255, 255, 0.498039); color: #a67f59;">=</span> Xmas95<span class="punctuation token" style="color: #999999;">.</span><span class="function token">getDate<span class="punctuation token" style="color: #999999;">(</span></span><span class="punctuation token" style="color: #999999;">)</span><span class="punctuation token" style="color: #999999;">;</span> +<pre class="brush:js language-js" style="padding: 1em 0px 1em 30px; border-left-width: 6px; border-left-style: solid; font-family: Consolas, Monaco, 'Andale Mono', monospace; font-size: 14px; text-shadow: none; direction: ltr; white-space: normal; background-color: rgba(234, 239, 242, 0.247059);"><code class="language-js" style="font-family: Consolas, Monaco, 'Andale Mono', monospace; color: inherit; text-shadow: none; direction: ltr; white-space: pre;">var Xmas95 = new Date("December 25, 1995 23:15:00"); +var day = Xmas95.getDate(); -<span class="function token">alert<span class="punctuation token" style="color: #999999;">(</span></span>day<span class="punctuation token" style="color: #999999;">)</span><span class="punctuation token" style="color: #999999;">;</span><span class="comment token" style="color: #708090; display: inherit;"> // 25</span></code></pre> +alert(day); // 25</code></pre> <h2 id="规范" style="margin-bottom: 20px; line-height: 30px;">规范</h2> diff --git a/files/zh-cn/web/javascript/reference/global_objects/date/getday/index.html b/files/zh-cn/web/javascript/reference/global_objects/date/getday/index.html index 86badcff49..e9b18b852e 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/date/getday/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/date/getday/index.html @@ -26,10 +26,10 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Date/getDay <p>下面第二条语句,基于{{jsxref("Date")}}对象 <code>Xmas95</code> 的值,把 1 赋值给 <code>weekday</code>。也就是说1995年12月25日是星期一。</p> -<pre class="brush:js language-js" style="padding: 1em 0px 1em 30px; border-left-width: 6px; border-left-style: solid; font-family: Consolas, Monaco, 'Andale Mono', monospace; font-size: 14px; text-shadow: none; direction: ltr; white-space: normal; background-color: rgba(234, 239, 242, 0.247059);"><code class="language-js" style="font-family: Consolas, Monaco, 'Andale Mono', monospace; color: inherit; text-shadow: none; direction: ltr; white-space: pre;"><span class="keyword token" style="color: #0077aa;">var</span> Xmas95 <span class="operator token" style="background: rgba(255, 255, 255, 0.498039); color: #a67f59;">=</span> <span class="keyword token" style="color: #0077aa;">new</span> <span class="class-name token">Date</span><span class="punctuation token" style="color: #999999;">(</span><span class="string token" style="color: #669900;">"December 25, 1995 23:15:30"</span><span class="punctuation token" style="color: #999999;">)</span><span class="punctuation token" style="color: #999999;">;</span> -<span class="keyword token" style="color: #0077aa;">var</span> weekday <span class="operator token" style="background: rgba(255, 255, 255, 0.498039); color: #a67f59;">=</span> Xmas95<span class="punctuation token" style="color: #999999;">.</span><span class="function token">getDay<span class="punctuation token" style="color: #999999;">(</span></span><span class="punctuation token" style="color: #999999;">)</span><span class="punctuation token" style="color: #999999;">;</span> +<pre class="brush:js language-js" style="padding: 1em 0px 1em 30px; border-left-width: 6px; border-left-style: solid; font-family: Consolas, Monaco, 'Andale Mono', monospace; font-size: 14px; text-shadow: none; direction: ltr; white-space: normal; background-color: rgba(234, 239, 242, 0.247059);"><code class="language-js" style="font-family: Consolas, Monaco, 'Andale Mono', monospace; color: inherit; text-shadow: none; direction: ltr; white-space: pre;">var Xmas95 = new Date("December 25, 1995 23:15:30"); +var weekday = Xmas95.getDay(); -<span class="function token">console.log<span class="punctuation token" style="color: #999999;">(</span></span>weekday<span class="punctuation token" style="color: #999999;">)</span><span class="punctuation token" style="color: #999999;">;</span><span class="comment token" style="color: #708090; display: inherit;"> // 1</span></code></pre> +console.log(weekday); // 1</code></pre> <div class="blockIndicator note"> <p dir="ltr">注意:如果需要,可以使用{{jsxref("DateTimeFormat", "Intl.DateTimeFormat")}}与一个额外的<code>options</code> 参数,从而返回这天的全称(如<code>"Monday"</code>).使用此方法,结果会更加国际化:</p> @@ -51,7 +51,7 @@ console.log(new Intl.DateTimeFormat('de-DE', options).format(Xmas95)); <th scope="col">注解</th> </tr> <tr> - <td>{{SpecName('ESDraft', '#sec-date.prototype.getday', 'Date.prototype.getDay')}}<span class="hidden"> </span><span class="hidden"> </span></td> + <td>{{SpecName('ESDraft', '#sec-date.prototype.getday', 'Date.prototype.getDay')}} </td> <td>{{Spec2('ESDraft')}} </td> <td></td> </tr> diff --git a/files/zh-cn/web/javascript/reference/global_objects/date/gethours/index.html b/files/zh-cn/web/javascript/reference/global_objects/date/gethours/index.html index c15bc0f6cf..eb8ad854e1 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/date/gethours/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/date/gethours/index.html @@ -29,10 +29,10 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Date/getHours <p>下面第二条语句,基于日期对象 <code>Xmas95 </code>的值,把 23 赋值给了变量 <code>hours。</code></p> -<pre class="brush:js language-js" style="padding: 1em 0px 1em 30px; border-left-width: 6px; border-left-style: solid; font-family: Consolas, Monaco, 'Andale Mono', monospace; font-size: 14px; text-shadow: none; direction: ltr; white-space: normal; background-color: rgba(234, 239, 242, 0.247059);"><code class="language-js" style="font-family: Consolas, Monaco, 'Andale Mono', monospace; color: inherit; text-shadow: none; direction: ltr; white-space: pre;"><span class="keyword token" style="color: #0077aa;">var</span> Xmas95 <span class="operator token" style="background: rgba(255, 255, 255, 0.498039); color: #a67f59;">=</span> <span class="keyword token" style="color: #0077aa;">new</span> <span class="class-name token">Date</span><span class="punctuation token" style="color: #999999;">(</span><span class="string token" style="color: #669900;">"December 25, 1995 23:15:00"</span><span class="punctuation token" style="color: #999999;">)</span><span class="punctuation token" style="color: #999999;">;</span> -<span class="keyword token" style="color: #0077aa;">var</span> hours <span class="operator token" style="background: rgba(255, 255, 255, 0.498039); color: #a67f59;">=</span> Xmas95<span class="punctuation token" style="color: #999999;">.</span><span class="function token">getHours<span class="punctuation token" style="color: #999999;">(</span></span><span class="punctuation token" style="color: #999999;">)</span><span class="punctuation token" style="color: #999999;">;</span> +<pre class="brush:js language-js" style="padding: 1em 0px 1em 30px; border-left-width: 6px; border-left-style: solid; font-family: Consolas, Monaco, 'Andale Mono', monospace; font-size: 14px; text-shadow: none; direction: ltr; white-space: normal; background-color: rgba(234, 239, 242, 0.247059);"><code class="language-js" style="font-family: Consolas, Monaco, 'Andale Mono', monospace; color: inherit; text-shadow: none; direction: ltr; white-space: pre;">var Xmas95 = new Date("December 25, 1995 23:15:00"); +var hours = Xmas95.getHours(); -<span class="function token">alert<span class="punctuation token" style="color: #999999;">(</span></span>hours<span class="punctuation token" style="color: #999999;">)</span><span class="punctuation token" style="color: #999999;">;</span><span class="comment token" style="color: #708090; display: inherit;"> // 23</span></code></pre> +alert(hours); // 23</code></pre> <h2 id="规范" style="margin-bottom: 20px; line-height: 30px;">规范</h2> diff --git a/files/zh-cn/web/javascript/reference/global_objects/date/getmilliseconds/index.html b/files/zh-cn/web/javascript/reference/global_objects/date/getmilliseconds/index.html index db20141cc4..15d556779d 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/date/getmilliseconds/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/date/getmilliseconds/index.html @@ -29,9 +29,9 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Date/getMilliseconds <p>下例中,将当前时间的毫秒数赋值给变量 <code>ms</code>。</p> -<pre class="brush: js language-js" style="padding: 1em 0px 1em 30px; border-left-width: 6px; border-left-style: solid; font-family: Consolas, Monaco, 'Andale Mono', monospace; font-size: 14px; text-shadow: none; direction: ltr; white-space: normal; background-color: rgba(234, 239, 242, 0.247059);"><code class="language-js" style="font-family: Consolas, Monaco, 'Andale Mono', monospace; color: inherit; text-shadow: none; direction: ltr; white-space: pre;"><span class="keyword token" style="color: #0077aa;">var</span> ms<span class="punctuation token" style="color: #999999;">;</span> -Today <span class="operator token" style="background: rgba(255, 255, 255, 0.498039); color: #a67f59;">=</span> <span class="keyword token" style="color: #0077aa;">new</span> <span class="class-name token">Date</span><span class="punctuation token" style="color: #999999;">(</span><span class="punctuation token" style="color: #999999;">)</span><span class="punctuation token" style="color: #999999;">;</span> -ms <span class="operator token" style="background: rgba(255, 255, 255, 0.498039); color: #a67f59;">=</span> Today<span class="punctuation token" style="color: #999999;">.</span><span class="function token">getMilliseconds<span class="punctuation token" style="color: #999999;">(</span></span><span class="punctuation token" style="color: #999999;">)</span><span class="punctuation token" style="color: #999999;">;</span></code></pre> +<pre class="brush: js language-js" style="padding: 1em 0px 1em 30px; border-left-width: 6px; border-left-style: solid; font-family: Consolas, Monaco, 'Andale Mono', monospace; font-size: 14px; text-shadow: none; direction: ltr; white-space: normal; background-color: rgba(234, 239, 242, 0.247059);"><code class="language-js" style="font-family: Consolas, Monaco, 'Andale Mono', monospace; color: inherit; text-shadow: none; direction: ltr; white-space: pre;">var ms; +Today = new Date(); +ms = Today.getMilliseconds();</code></pre> <h2 id="规范" style="margin-bottom: 20px; line-height: 30px;">规范</h2> diff --git a/files/zh-cn/web/javascript/reference/global_objects/date/getminutes/index.html b/files/zh-cn/web/javascript/reference/global_objects/date/getminutes/index.html index 5bcbcfc724..7a1fd0f433 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/date/getminutes/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/date/getminutes/index.html @@ -27,8 +27,8 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Date/getMinutes <p>下例中,第二行语句运行过后,变量 <code>minutes </code>的值为15,也就是说 <code>Xmas95 </code>这个日期对象的值为某时15分某秒。</p> -<pre class="brush:js language-js" style="padding: 1em 0px 1em 30px; border-left-width: 6px; border-left-style: solid; font-family: Consolas, Monaco, 'Andale Mono', monospace; font-size: 14px; text-shadow: none; direction: ltr; white-space: normal; background-color: rgba(234, 239, 242, 0.247059);"><code class="language-js" style="font-family: Consolas, Monaco, 'Andale Mono', monospace; color: inherit; text-shadow: none; direction: ltr; white-space: pre;"><span class="keyword token" style="color: #0077aa;">var</span> Xmas95 <span class="operator token" style="background: rgba(255, 255, 255, 0.498039); color: #a67f59;">=</span> <span class="keyword token" style="color: #0077aa;">new</span> <span class="class-name token">Date</span><span class="punctuation token" style="color: #999999;">(</span><span class="string token" style="color: #669900;">"December 25, 1995 23:15:00"</span><span class="punctuation token" style="color: #999999;">)</span><span class="punctuation token" style="color: #999999;">;</span> -<span class="keyword token" style="color: #0077aa;">var</span> minutes <span class="operator token" style="background: rgba(255, 255, 255, 0.498039); color: #a67f59;">=</span> Xmas95<span class="punctuation token" style="color: #999999;">.</span><span class="function token">getMinutes<span class="punctuation token" style="color: #999999;">(</span></span><span class="punctuation token" style="color: #999999;">)</span><span class="punctuation token" style="color: #999999;">;</span></code></pre> +<pre class="brush:js language-js" style="padding: 1em 0px 1em 30px; border-left-width: 6px; border-left-style: solid; font-family: Consolas, Monaco, 'Andale Mono', monospace; font-size: 14px; text-shadow: none; direction: ltr; white-space: normal; background-color: rgba(234, 239, 242, 0.247059);"><code class="language-js" style="font-family: Consolas, Monaco, 'Andale Mono', monospace; color: inherit; text-shadow: none; direction: ltr; white-space: pre;">var Xmas95 = new Date("December 25, 1995 23:15:00"); +var minutes = Xmas95.getMinutes();</code></pre> <p dir="ltr"><strong style="font-size: 2.142857142857143rem; font-weight: 700; letter-spacing: -1px; line-height: 30px;">规范</strong></p> diff --git a/files/zh-cn/web/javascript/reference/global_objects/date/getseconds/index.html b/files/zh-cn/web/javascript/reference/global_objects/date/getseconds/index.html index 83a899886e..457f166047 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/date/getseconds/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/date/getseconds/index.html @@ -29,8 +29,8 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Date/getSeconds <p>下面第二条语句,基于日期对象 <code>Xmas95</code> 的值,把 30 赋值给变量 <code>secs</code>。</p> -<pre class="brush:js language-js" style="padding: 1em 0px 1em 30px; border-left-width: 6px; border-left-style: solid; font-family: Consolas, Monaco, 'Andale Mono', monospace; font-size: 14px; text-shadow: none; direction: ltr; white-space: normal; background-color: rgba(234, 239, 242, 0.247059);"><code class="language-js" style="font-family: Consolas, Monaco, 'Andale Mono', monospace; color: inherit; text-shadow: none; direction: ltr; white-space: pre;"><span class="keyword token" style="color: #0077aa;">var</span> Xmas95 <span class="operator token" style="background: rgba(255, 255, 255, 0.498039); color: #a67f59;">=</span> <span class="keyword token" style="color: #0077aa;">new</span> <span class="class-name token">Date</span><span class="punctuation token" style="color: #999999;">(</span><span class="string token" style="color: #669900;">"December 25, 1995 23:15:30"</span><span class="punctuation token" style="color: #999999;">)</span><span class="punctuation token" style="color: #999999;">;</span> -<span class="keyword token" style="color: #0077aa;">var</span> secs <span class="operator token" style="background: rgba(255, 255, 255, 0.498039); color: #a67f59;">=</span> Xmas95<span class="punctuation token" style="color: #999999;">.</span><span class="function token">getSeconds<span class="punctuation token" style="color: #999999;">(</span></span><span class="punctuation token" style="color: #999999;">)</span><span class="punctuation token" style="color: #999999;">;</span></code></pre> +<pre class="brush:js language-js" style="padding: 1em 0px 1em 30px; border-left-width: 6px; border-left-style: solid; font-family: Consolas, Monaco, 'Andale Mono', monospace; font-size: 14px; text-shadow: none; direction: ltr; white-space: normal; background-color: rgba(234, 239, 242, 0.247059);"><code class="language-js" style="font-family: Consolas, Monaco, 'Andale Mono', monospace; color: inherit; text-shadow: none; direction: ltr; white-space: pre;">var Xmas95 = new Date("December 25, 1995 23:15:30"); +var secs = Xmas95.getSeconds();</code></pre> <div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; line-height: inherit; top: 0px; background: transparent;"> </div> diff --git a/files/zh-cn/web/javascript/reference/global_objects/date/now/index.html b/files/zh-cn/web/javascript/reference/global_objects/date/now/index.html index b7153612a2..fd0c8dd482 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/date/now/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/date/now/index.html @@ -30,9 +30,9 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Date/now <p>因为 <code>now()</code> 是 {{jsxref("Date")}} 的一个静态函数,所以必须以 <code>Date.now()</code> 的形式来使用。</p> -<h2 id="时间精度被降低"><span class="tlid-translation translation" lang="zh-CN"><span title="">时间精度被降低</span></span></h2> +<h2 id="时间精度被降低">时间精度被降低</h2> -<p><span class="tlid-translation translation" lang="zh-CN"><span title="">为了提供针对定时攻击和指纹追踪的保护,</span></span><code>Date.now()</code> <span class="tlid-translation translation" lang="zh-CN"><span title="">的精度可能会根据浏览器的高级设置项目而被取整。</span></span><br> +<p>为了提供针对定时攻击和指纹追踪的保护,<code>Date.now()</code> 的精度可能会根据浏览器的高级设置项目而被取整。<br> 在 Firefox 中,默认启用 <code>privacy.reduceTimerPrecision</code> 设置项,在 Firefox 59 中,默认被取整至 20 微秒;在 Firefox 60 中,则被取整至 2 毫秒。</p> <pre class="brush: js">// reduced time precision (2ms) in Firefox 60 diff --git a/files/zh-cn/web/javascript/reference/global_objects/date/parse/index.html b/files/zh-cn/web/javascript/reference/global_objects/date/parse/index.html index 701f6fc103..9646b069da 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/date/parse/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/date/parse/index.html @@ -52,7 +52,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Date/parse <p>由于在解析日期字符串时存在偏差会导致结果不一致,因此推荐始终手动解析日期字符串,特别是不同的ECMAScript实现会把诸如“2015-10-12 12:00:00”的字符串解析为NaN,UTC或者本地时间。</p> -<h3 id="ECMAScript_5_ISO-8601_日期格式支持">ECMAScript 5 <span class="caps">ISO</span>-8601 日期格式支持</h3> +<h3 id="ECMAScript_5_ISO-8601_日期格式支持">ECMAScript 5 ISO-8601 日期格式支持</h3> <p>另外,日期时间字符串也可以使用 <a href="http://www.w3.org/TR/NOTE-datetime" title="http://www.w3.org/TR/NOTE-datetime">ISO 8601</a> 格式。例如,"<code>2011-10-10</code>" (仅日期)或 "<code>2011-10-10T14:48:00</code>" (日期和时间)能够作为参数被传递和解析。 如果参数字符串只包含日期格式,那么将会使用UTC时区来解析该参数。而如果是<a href="http://www.w3.org/TR/NOTE-datetime" title="http://www.w3.org/TR/NOTE-datetime">ISO 8601</a> 格式中规定的时间加日期的格式,则将会被作为本地时区处理。</p> @@ -70,26 +70,26 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Date/parse <p>但是, 在如 ECMA-262 规范中定义的情况,如果因为无效值而导致日期字符串不能被识别为 ISO 格式时,根据浏览器和给定的值不同,返回值可以是,也可以不是 {{jsxref("NaN")}} 。比如:</p> -<pre class="brush: js line-numbers language-js"><code class="language-js"><span class="comment token">// 包含无效值的非 ISO 格式字符串</span> -<span class="keyword token">new</span> <span class="class-name token">Date</span><span class="punctuation token">(</span><span class="string token">'23/25/2014'</span><span class="punctuation token">)</span><span class="punctuation token">;</span></code></pre> +<pre class="brush: js line-numbers language-js"><code class="language-js">// 包含无效值的非 ISO 格式字符串 +new Date('23/25/2014');</code></pre> <p>在 Firefox 30 中会被识别为本地时区的2015年12月25日,而在 Safari 7 中则是无效日期。但是,如果字符串被识别为 ISO 格式并且包含无效值,则在所有遵循 ES5 或者更新标准的浏览器中都会返回 {{jsxref("NaN")}} 。</p> -<pre class="brush: js line-numbers language-js"><code class="language-js"><span class="comment token">// 包含无效值的 ISO 格式字符串</span> -<span class="keyword token">new</span> <span class="class-name token">Date</span><span class="punctuation token">(</span><span class="string token">'2014-25-23'</span><span class="punctuation token">)</span><span class="punctuation token">.</span><span class="function token">toISOString</span><span class="punctuation token">(</span><span class="punctuation token">)</span><span class="punctuation token">;</span> -<span class="comment token">// 在所有遵循 ES5的浏览器中返回 "RangeError: invalid date"</span></code></pre> +<pre class="brush: js line-numbers language-js"><code class="language-js">// 包含无效值的 ISO 格式字符串 +new Date('2014-25-23').toISOString(); +// 在所有遵循 ES5的浏览器中返回 "RangeError: invalid date"</code></pre> <p>SpiderMonkey 的引擎策略可以在 <a href="http://mxr.mozilla.org/mozilla-central/source/js/src/jsdate.cpp?rev=64553c483cd1#889"><code>jsdate.cpp</code></a> 中找到。字符串 <code>"10 06 2014"</code> 可以作为非 ISO 格式字符串使用自定义处理方式的例子。参见这篇关于解析如何进行的<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1023155#c6">粗略纲要</a>。</p> -<pre class="brush: js line-numbers language-js"><code class="language-js"><span class="keyword token">new</span> <span class="class-name token">Date</span><span class="punctuation token">(</span><span class="string token">'10 06 2014'</span><span class="punctuation token">)</span><span class="punctuation token">;</span></code></pre> +<pre class="brush: js line-numbers language-js"><code class="language-js">new Date('10 06 2014');</code></pre> <p>将会被解析为本地时间 2014年10月6日,而不是6月10日。另一个例子</p> -<pre class="brush: js line-numbers language-js"><code class="language-js"><span class="keyword token">new</span> <span class="class-name token">Date</span><span class="punctuation token">(</span><span class="string token">'foo-bar 2014'</span><span class="punctuation token">)</span><span class="punctuation token">.</span><span class="function token">toString</span><span class="punctuation token">(</span><span class="punctuation token">)</span><span class="punctuation token">;</span> -<span class="comment token">// 返回: "Invalid Date"</span> +<pre class="brush: js line-numbers language-js"><code class="language-js">new Date('foo-bar 2014').toString(); +// 返回: "Invalid Date" -Date<span class="punctuation token">.</span><span class="function token">parse</span><span class="punctuation token">(</span><span class="string token">'foo-bar 2014'</span><span class="punctuation token">)</span><span class="punctuation token">;</span> -<span class="comment token">// 返回: NaN</span></code></pre> +Date.parse('foo-bar 2014'); +// 返回: NaN</code></pre> <h2 id="Examples" name="Examples">例子</h2> @@ -97,7 +97,7 @@ Date<span class="punctuation token">.</span><span class="function token">parse</ <p>如果 <code>IPOdate</code> 是一个已经存在的 {{jsxref("Date")}} 对象,则可以把其设置为本地时间 1995年8月9日。如下:</p> -<pre class="brush: js line-numbers language-js"><code class="language-js">IPOdate<span class="punctuation token">.</span><span class="function token">setTime</span><span class="punctuation token">(</span>Date<span class="punctuation token">.</span><span class="function token">parse</span><span class="punctuation token">(</span><span class="string token">'Aug 9, 1995'</span><span class="punctuation token">)</span><span class="punctuation token">)</span><span class="punctuation token">;</span></code></pre> +<pre class="brush: js line-numbers language-js"><code class="language-js">IPOdate.setTime(Date.parse('Aug 9, 1995'));</code></pre> <p>其他一些解析非标准格式日期的例子:</p> diff --git a/files/zh-cn/web/javascript/reference/global_objects/date/setfullyear/index.html b/files/zh-cn/web/javascript/reference/global_objects/date/setfullyear/index.html index 72a0583a2d..ad8ffc0c33 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/date/setfullyear/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/date/setfullyear/index.html @@ -36,8 +36,8 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Date/setFullYear <h3 id="Example:_Using_setFullYear" name="Example:_Using_setFullYear">例子:使用<code>setFullYear</code>方法</h3> -<pre class="brush:js language-js" style="padding: 1em 0px 1em 30px; border-left-width: 6px; border-left-style: solid; font-family: Consolas, Monaco, 'Andale Mono', monospace; font-size: 14px; text-shadow: none; direction: ltr; white-space: normal; background-color: rgba(234, 239, 242, 0.247059);"><code class="language-js" style="font-family: Consolas, Monaco, 'Andale Mono', monospace; color: inherit; text-shadow: none; direction: ltr; white-space: pre;"><span class="keyword token" style="color: #0077aa;">var</span> theBigDay <span class="operator token" style="background: rgba(255, 255, 255, 0.498039); color: #a67f59;">=</span> <span class="keyword token" style="color: #0077aa;">new</span> <span class="class-name token">Date</span><span class="punctuation token" style="color: #999999;">(</span><span class="punctuation token" style="color: #999999;">)</span><span class="punctuation token" style="color: #999999;">;</span> -theBigDay<span class="punctuation token" style="color: #999999;">.</span><span class="function token">setFullYear<span class="punctuation token" style="color: #999999;">(</span></span><span class="number token" style="color: #990055;">1997</span><span class="punctuation token" style="color: #999999;">)</span><span class="punctuation token" style="color: #999999;">;</span></code></pre> +<pre class="brush:js language-js" style="padding: 1em 0px 1em 30px; border-left-width: 6px; border-left-style: solid; font-family: Consolas, Monaco, 'Andale Mono', monospace; font-size: 14px; text-shadow: none; direction: ltr; white-space: normal; background-color: rgba(234, 239, 242, 0.247059);"><code class="language-js" style="font-family: Consolas, Monaco, 'Andale Mono', monospace; color: inherit; text-shadow: none; direction: ltr; white-space: pre;">var theBigDay = new Date(); +theBigDay.setFullYear(1997);</code></pre> <h2 id="规范">规范</h2> diff --git a/files/zh-cn/web/javascript/reference/global_objects/date/sethours/index.html b/files/zh-cn/web/javascript/reference/global_objects/date/sethours/index.html index 5b0315f92d..43786dadd9 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/date/sethours/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/date/sethours/index.html @@ -13,7 +13,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Date/setHours <h2 id="Syntax" name="Syntax">语法</h2> -<pre class="syntaxbox">dateObj.setHours(<em>hoursValue</em>[, <em>minutesValue</em>[, <em>secondsValue</em><span style="line-height: normal;">[</span><span style="line-height: normal;">, </span><em>msValue</em><span style="line-height: normal;">]]])</span> +<pre class="syntaxbox">dateObj.setHours(<em>hoursValue</em>[, <em>minutesValue</em>[, <em>secondsValue</em>[, <em>msValue</em>]]]) </pre> <h3 id="Versions_prior_to_JavaScript_1.3" name="Versions_prior_to_JavaScript_1.3">JavaScript 1.3版本之前</h3> diff --git a/files/zh-cn/web/javascript/reference/global_objects/date/setutcfullyear/index.html b/files/zh-cn/web/javascript/reference/global_objects/date/setutcfullyear/index.html index 9d448b59df..fd83af1c4e 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/date/setutcfullyear/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/date/setutcfullyear/index.html @@ -84,7 +84,7 @@ theBigDay.setUTCFullYear(1997); <p>{{Compat("javascript.builtins.Date.setUTCFullYear")}}</p> </div> -<p><span style="font-size: 30.002px; letter-spacing: -1px; line-height: 30.002px;"><strong>相关连接</strong></span></p> +<p><strong>相关连接</strong></p> <ul> <li>{{jsxref("Date.prototype.getUTCFullYear()")}}</li> diff --git a/files/zh-cn/web/javascript/reference/global_objects/date/tolocaledatestring/index.html b/files/zh-cn/web/javascript/reference/global_objects/date/tolocaledatestring/index.html index 3089a5fb63..407050f518 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/date/tolocaledatestring/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/date/tolocaledatestring/index.html @@ -73,7 +73,7 @@ alert(date.toLocaleDateString("ko-KR")); // Arabic in most Arabic speaking countries uses real Arabic digits alert(date.toLocaleDateString("ar-EG")); -// → "<span dir="rtl">٢٠/١٢/٢٠١٢</span>" +// → "٢٠/١٢/٢٠١٢" // for Japanese, applications may want to use the Japanese calendar, // where 2012 was the year 24 of the Heisei era diff --git a/files/zh-cn/web/javascript/reference/global_objects/date/tolocalestring/index.html b/files/zh-cn/web/javascript/reference/global_objects/date/tolocalestring/index.html index be2e721ee2..3c9ecb2a58 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/date/tolocalestring/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/date/tolocalestring/index.html @@ -5,7 +5,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Date/toLocaleString --- <div>{{JSRef("Global_Objects", "Date")}}</div> -<p><code><strong>toLocaleString()</strong></code> <span style="line-height: 1.5;">方法返回该日期对象的字符串,该字符串格式因不同语言而不同。新增的参数 </span><code style="font-style: normal; line-height: 1.5;">locales</code><span style="line-height: 1.5;"> 和 </span><code style="font-style: normal; line-height: 1.5;">options</code><span style="line-height: 1.5;"> 使程序能够指定使用哪种语言格式化规则,允许定制该方法的表现(behavior)。在旧版本浏览器中, </span><code style="font-style: normal; line-height: 1.5;">locales</code><span style="line-height: 1.5;"> 和 </span><code style="font-style: normal; line-height: 1.5;">options</code><span style="line-height: 1.5;"> 参数被忽略,使用的语言环境和返回的字符串格式是各自独立实现的。</span></p> +<p><code><strong>toLocaleString()</strong></code> 方法返回该日期对象的字符串,该字符串格式因不同语言而不同。新增的参数 <code style="font-style: normal; line-height: 1.5;">locales</code> 和 <code style="font-style: normal; line-height: 1.5;">options</code> 使程序能够指定使用哪种语言格式化规则,允许定制该方法的表现(behavior)。在旧版本浏览器中, <code style="font-style: normal; line-height: 1.5;">locales</code> 和 <code style="font-style: normal; line-height: 1.5;">options</code> 参数被忽略,使用的语言环境和返回的字符串格式是各自独立实现的。</p> <div>{{EmbedInteractiveExample("pages/js/date-tolocalestring.html")}}</div> @@ -75,7 +75,7 @@ alert(date.toLocaleString("ko-KR")); // 大多数阿拉伯语国家的阿拉伯语使用阿拉伯数字 alert(date.toLocaleString("ar-EG")); -// → "<span dir="rtl">٢٠/١٢/٢٠١٢ ٥:٠٠:٠٠ ص</span>" +// → "٢٠/١٢/٢٠١٢ ٥:٠٠:٠٠ ص" //在日本,应用可能想要使用日本日历, //2012 是平成24年(平成是是日本天皇明仁的年号,由1989年1月8日起开始计算直至现在) diff --git a/files/zh-cn/web/javascript/reference/global_objects/date/tolocaletimestring/index.html b/files/zh-cn/web/javascript/reference/global_objects/date/tolocaletimestring/index.html index c19d137c7a..2f31d53e2d 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/date/tolocaletimestring/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/date/tolocaletimestring/index.html @@ -5,7 +5,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Date/toLocaleTimeString --- <div>{{JSRef("Global_Objects", "Date")}}</div> -<p>The <code><strong>toLocaleTimeString()</strong></code> <span style="line-height: 1.5;">方法返回该日期对象时间部分的字符串,该字符串格式因不同语言而不同。新增的参数 </span><code style="font-style: normal; line-height: 1.5;">locales</code><span style="line-height: 1.5;"> 和 </span><code style="font-style: normal; line-height: 1.5;">options</code><span style="line-height: 1.5;"> 使程序能够指定使用哪种语言格式化规则,允许定制该方法的表现(behavior)。在旧版本浏览器中, </span><code style="font-style: normal; line-height: 1.5;">locales</code><span style="line-height: 1.5;"> 和 </span><code style="font-style: normal; line-height: 1.5;">options</code><span style="line-height: 1.5;"> 参数被忽略,使用的语言环境和返回的字符串格式是各自独立实现的。</span></p> +<p>The <code><strong>toLocaleTimeString()</strong></code> 方法返回该日期对象时间部分的字符串,该字符串格式因不同语言而不同。新增的参数 <code style="font-style: normal; line-height: 1.5;">locales</code> 和 <code style="font-style: normal; line-height: 1.5;">options</code> 使程序能够指定使用哪种语言格式化规则,允许定制该方法的表现(behavior)。在旧版本浏览器中, <code style="font-style: normal; line-height: 1.5;">locales</code> 和 <code style="font-style: normal; line-height: 1.5;">options</code> 参数被忽略,使用的语言环境和返回的字符串格式是各自独立实现的。</p> <div>{{EmbedInteractiveExample("pages/js/date-tolocaletimestring.html")}}</div> @@ -73,7 +73,7 @@ alert(date.toLocaleTimeString("ko-KR")); // Arabic in most Arabic speaking countries uses real Arabic digits alert(date.toLocaleTimeString("ar-EG")); -// → "<span dir="rtl">٧:٠٠:٠٠ م</span>" +// → "٧:٠٠:٠٠ م" // when requesting a language that may not be supported, such as // Balinese, include a fallback language, in this case Indonesian diff --git a/files/zh-cn/web/javascript/reference/global_objects/decodeuri/index.html b/files/zh-cn/web/javascript/reference/global_objects/decodeuri/index.html index ca777f1f3c..d988fc7557 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/decodeuri/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/decodeuri/index.html @@ -97,8 +97,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/decodeURI <p>{{Compat("javascript.builtins.decodeURI")}}</p> -<h2 id="相关链接"><br> - <span style="">相关链接</span></h2> +<h2 id="相关链接">相关链接</h2> <div id="compat-mobile"></div> diff --git a/files/zh-cn/web/javascript/reference/global_objects/decodeuricomponent/index.html b/files/zh-cn/web/javascript/reference/global_objects/decodeuricomponent/index.html index a45b313f7c..8593a8a074 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/decodeuricomponent/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/decodeuricomponent/index.html @@ -25,11 +25,11 @@ translation_of: Web/JavaScript/Reference/Global_Objects/decodeURIComponent <h3 id="返回值">返回值</h3> -<p><span class="tlid-translation translation" lang="zh-CN"><span title="">一个解码后的统一资源标识符(URI)字符串,处理前的URI经过了给定格式的编码。</span></span></p> +<p>一个解码后的统一资源标识符(URI)字符串,处理前的URI经过了给定格式的编码。</p> <h3 id="异常">异常</h3> -<p>当该方法使用不当时,将会抛出一个{{jsxref("URIError")}}(<span class="tlid-translation translation" lang="zh-CN"><span title="">“</span></span><span class="tlid-translation translation" lang="zh-CN"><span title="">格式错误的URI序列</span></span><span class="tlid-translation translation" lang="zh-CN"><span title="">”</span></span>)异常。</p> +<p>当该方法使用不当时,将会抛出一个{{jsxref("URIError")}}(“格式错误的URI序列”)异常。</p> <h2 id="描述">描述</h2> diff --git a/files/zh-cn/web/javascript/reference/global_objects/error/index.html b/files/zh-cn/web/javascript/reference/global_objects/error/index.html index c8aa8b581e..b9334c7969 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/error/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/error/index.html @@ -9,7 +9,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Error --- <p>{{JSRef}}</p> -<p><span style="line-height: inherit;">通过<strong>Error</strong>的构造器可以创建一个错误对象。当运行时错误产生时,Error的实例对象会被抛出。Error对象</span>也<span style="line-height: inherit;">可用于用户自定义的异常的基础对象。下面列出了各种内建的标准错误类型。</span></p> +<p>通过<strong>Error</strong>的构造器可以创建一个错误对象。当运行时错误产生时,Error的实例对象会被抛出。Error对象也可用于用户自定义的异常的基础对象。下面列出了各种内建的标准错误类型。</p> <h2 id="Syntax" name="Syntax">语法</h2> @@ -24,19 +24,19 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Error <dl> <dt><code>fileName </code>{{non-standard_inline}}</dt> - <dd>可选。被创建的<span style="font-family: monospace; line-height: inherit;">Error对象的fileName属性值。</span><span style="line-height: inherit;">默认是调用Error构造器代码所在的文件 的名字。</span></dd> + <dd>可选。被创建的Error对象的fileName属性值。默认是调用Error构造器代码所在的文件 的名字。</dd> </dl> <dl> <dt><code>lineNumber </code>{{non-standard_inline}}</dt> - <dd>可选。被创建的<span style="font-family: monospace; line-height: inherit;">Error对象的lineNumber属性值。默认是</span><span style="line-height: inherit;">调用Error构造器代码所在的文件的行号</span><span style="font-family: monospace; line-height: inherit;">。</span></dd> + <dd>可选。被创建的Error对象的lineNumber属性值。默认是调用Error构造器代码所在的文件的行号。</dd> </dl> <h2 id="Description" name="Description">描述</h2> <p>当代码运行时的发生错误,会创建新的<code>Error</code> 对象,并将其抛出。</p> -<p><span style="line-height: inherit;">该页面描述了Error对象自身的使用,以及其构造函数的使用</span><span style="line-height: inherit;">. 关于Error实例的内部属性和方法,请看</span> {{jsxref("Error.prototype")}}。</p> +<p>该页面描述了Error对象自身的使用,以及其构造函数的使用. 关于Error实例的内部属性和方法,请看 {{jsxref("Error.prototype")}}。</p> <h3 id="作为函数使用">作为函数使用</h3> @@ -49,7 +49,7 @@ const y = new Error('I was constructed via the "new" keyword!');</code></pre> <h3 id="Error_types" name="Error_types">Error 类型</h3> -<p>除了通用的<span style="font-family: courier new,andale mono,monospace; line-height: inherit;">Error构造函数外,</span>JavaScript<span style="font-family: courier new,andale mono,monospace; line-height: inherit;">还有6个其他类型的错误构造函数。更多客户端异常,详见</span><span style="line-height: inherit;"> </span><a href="/en/JavaScript/Guide/Statements#Exception_Handling_Statements" style="line-height: inherit;" title="en/JavaScript/Guide/Statements#Exception Handling Statements">Exception Handling Statements</a>。</p> +<p>除了通用的Error构造函数外,JavaScript还有6个其他类型的错误构造函数。更多客户端异常,详见 <a href="/en/JavaScript/Guide/Statements#Exception_Handling_Statements" style="line-height: inherit;" title="en/JavaScript/Guide/Statements#Exception Handling Statements">Exception Handling Statements</a>。</p> <dl> <dt><strong style="font-weight: bold;">{{jsxref("EvalError")}}</strong></dt> @@ -60,7 +60,7 @@ const y = new Error('I was constructed via the "new" keyword!');</code></pre> <dl> <dt><strong style="font-weight: bold;">{{jsxref("RangeError", "RangeError")}}</strong></dt> - <dd>创建一个error实例,表示错误的原因:<span style="line-height: inherit;">数值变量或参数超出其有效范围</span><span style="line-height: inherit;">。</span></dd> + <dd>创建一个error实例,表示错误的原因:数值变量或参数超出其有效范围。</dd> </dl> <dl> @@ -70,7 +70,7 @@ const y = new Error('I was constructed via the "new" keyword!');</code></pre> <dl> <dt><strong style="font-weight: bold;">{{jsxref("SyntaxError")}}</strong></dt> - <dd>创建一个error实例,表示错误的原因:{{jsxref("Global_Objects/eval", "eval()")}}在解析代码的过程中发生的语法错误<span style="line-height: inherit;">。</span></dd> + <dd>创建一个error实例,表示错误的原因:{{jsxref("Global_Objects/eval", "eval()")}}在解析代码的过程中发生的语法错误。</dd> </dl> <dl> @@ -80,7 +80,7 @@ const y = new Error('I was constructed via the "new" keyword!');</code></pre> <dl> <dt><strong style="font-weight: bold;">{{jsxref("URIError")}}</strong></dt> - <dd>创建一个error实例,表示错误的原因:给 {{jsxref("Global_Objects/encodeURI", "encodeURI()")}}<span style="line-height: inherit;">或 </span> {{jsxref("Global_Objects/decodeURI", "decodeURI()")}}<span style="line-height: inherit;">传递的参数无效。</span></dd> + <dd>创建一个error实例,表示错误的原因:给 {{jsxref("Global_Objects/encodeURI", "encodeURI()")}}或 {{jsxref("Global_Objects/decodeURI", "decodeURI()")}}传递的参数无效。</dd> </dl> <h2 id="Properties" name="Properties">属性</h2> diff --git a/files/zh-cn/web/javascript/reference/global_objects/error/name/index.html b/files/zh-cn/web/javascript/reference/global_objects/error/name/index.html index 85eba29c8a..13232d69d9 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/error/name/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/error/name/index.html @@ -7,11 +7,11 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Error/name <h2 id="Summary" name="Summary">概述</h2> -<p><code style="font-style: normal; line-height: 19.0909080505371px;"><strong>name</strong></code><span style="line-height: 19.0909080505371px;"> </span>属性表示error类型的名称.初始值为"Error".</p> +<p><code style="font-style: normal; line-height: 19.0909080505371px;"><strong>name</strong></code> 属性表示error类型的名称.初始值为"Error".</p> <h2 id="Description" name="Description">描述</h2> -<p>默认情况下,<span style="line-height: 19.0909080505371px;">{{jsxref("Error")}}</span>对象的<code>name</code>属性值为"Error".<code>name属性和</code><span style="line-height: 19.0909080505371px;">{{jsxref("Error.prototype.message", "message")}}</span>属性一起,通过调用<span style="line-height: 19.0909080505371px;">{{jsxref("Error.prototype.toString()")}}</span>方法,会作为最后异常信息的字符串表示.</p> +<p>默认情况下,{{jsxref("Error")}}对象的<code>name</code>属性值为"Error".<code>name属性和</code>{{jsxref("Error.prototype.message", "message")}}属性一起,通过调用{{jsxref("Error.prototype.toString()")}}方法,会作为最后异常信息的字符串表示.</p> <h2 id="Examples" name="Examples">示例</h2> diff --git a/files/zh-cn/web/javascript/reference/global_objects/function/apply/index.html b/files/zh-cn/web/javascript/reference/global_objects/function/apply/index.html index 0bf0414cf8..d345215619 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/function/apply/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/function/apply/index.html @@ -11,7 +11,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Function/apply <p><strong><code>apply()</code></strong> 方法调用一个具有给定<code>this</code>值的函数,以及以一个数组(或<a href="/zh-CN/docs/Web/JavaScript/Guide/Indexed_collections#Working_with_array-like_objects">类数组对象</a>)的形式提供的参数。</p> -<div class="note"><strong>注意:</strong><span style="line-height: 1.5;">call()方法的作用和 apply() 方法类似,区别就是<code>call()</code>方法接受的是<strong>参数列表</strong>,而<code>apply()</code>方法接受的是<strong>一个参数数组</strong>。</span></div> +<div class="note"><strong>注意:</strong>call()方法的作用和 apply() 方法类似,区别就是<code>call()</code>方法接受的是<strong>参数列表</strong>,而<code>apply()</code>方法接受的是<strong>一个参数数组</strong>。</div> <div>{{EmbedInteractiveExample("pages/js/function-apply.html")}}</div> @@ -36,9 +36,9 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Function/apply <h2 id="Description" name="Description">描述</h2> -<p><span style="line-height: 1.5;">在调用一个存在的函数时,你可以为其指定一个 <code>this</code> 对象。 <code>this</code></span> <span style="line-height: 1.5;">指当前对象,也就是正在调用这个函数的对象。 使用 <code>apply</code>, 你可以只写一次这个方法然后在另一个对象中继承它,而不用在新对象中重复写该方法。</span></p> +<p>在调用一个存在的函数时,你可以为其指定一个 <code>this</code> 对象。 <code>this</code> 指当前对象,也就是正在调用这个函数的对象。 使用 <code>apply</code>, 你可以只写一次这个方法然后在另一个对象中继承它,而不用在新对象中重复写该方法。</p> -<p><code>apply</code> 与 {{jsxref("Function.call", "call()")}} 非常相似,不同之处在于提供参数的方式。<code style="font-size: 14px;">apply</code> 使用参数数组而不是一组参数列表。<code>apply</code> 可以使用数组字面量(array literal)<span style="line-height: 1.5;">,如 </span><code>fun.apply(this, ['eat', 'bananas'])</code><span style="line-height: 1.5;">,或数组对象,</span><span style="line-height: 1.5;"> 如 </span><code>fun.apply(this, new Array('eat', 'bananas'))</code><span style="line-height: 1.5;">。</span></p> +<p><code>apply</code> 与 {{jsxref("Function.call", "call()")}} 非常相似,不同之处在于提供参数的方式。<code style="font-size: 14px;">apply</code> 使用参数数组而不是一组参数列表。<code>apply</code> 可以使用数组字面量(array literal),如 <code>fun.apply(this, ['eat', 'bananas'])</code>,或数组对象, 如 <code>fun.apply(this, new Array('eat', 'bananas'))</code>。</p> <p>你也可以使用 {{jsxref("Functions/arguments", "arguments")}}对象作为 <code>argsArray</code> 参数。 <code>arguments</code> 是一个函数的局部变量。 它可以被用作被调用对象的所有未指定的参数。 这样,你在使用apply函数的时候就不需要知道被调用对象的所有参数。 你可以使用arguments来把所有的参数传递给被调用对象。 被调用对象接下来就负责处理这些参数。</p> @@ -108,7 +108,7 @@ var min = minOfArray([5, 6, 2, 3, 7]); <h3 id="Using_apply_to_chain_constructors" name="Using_apply_to_chain_constructors">使用apply来链接构造器</h3> -<p>你可以使用apply来链接一个对象<a href="/zh-CN/docs/JavaScript/Reference/Operators/new" title="JavaScript/Reference/Operators/new">构造器</a>,类似于Java。在接下来的例子中我们会创建一个全局<a href="/zh-CN/docs/JavaScript/Reference/Global_Objects/Function" title="JavaScript/Reference/Global_Objects/Function"><code>Function</code></a> <span style="color: #000000; display: inline !important; float: none; font-family: 'microsoft yahei'; font-size: 18px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 28.8px; text-align: left; text-indent: 0px; text-transform: none; white-space: normal;">对象的</span><span style="color: #000000; font-family: 'microsoft yahei'; font-size: 18px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 28.8px; text-align: left; text-indent: 0px; text-transform: none; white-space: normal;">construct</span><span style="color: #000000; font-family: 'microsoft yahei'; font-size: 18px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 1.6; text-align: left; text-indent: 0px; text-transform: none; white-space: normal;">方法</span> ,来使你能够在构造器中使用一个类数组对象而非参数列表。</p> +<p>你可以使用apply来链接一个对象<a href="/zh-CN/docs/JavaScript/Reference/Operators/new" title="JavaScript/Reference/Operators/new">构造器</a>,类似于Java。在接下来的例子中我们会创建一个全局<a href="/zh-CN/docs/JavaScript/Reference/Global_Objects/Function" title="JavaScript/Reference/Global_Objects/Function"><code>Function</code></a> 对象的construct方法 ,来使你能够在构造器中使用一个类数组对象而非参数列表。</p> <pre class="brush: js notranslate">Function.prototype.construct = function (aArgs) { var oNew = Object.create(this.prototype); diff --git a/files/zh-cn/web/javascript/reference/global_objects/function/caller/index.html b/files/zh-cn/web/javascript/reference/global_objects/function/caller/index.html index a850d41582..ba3ce01a26 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/function/caller/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/function/caller/index.html @@ -58,7 +58,7 @@ while (f) { <pre class="brush: js">function myFunc() { if (myFunc.caller == null) { - return ("<span><span class="string">该函数在全局作用域内被调用</span></span>!"); + return ("该函数在全局作用域内被调用!"); } else return ("调用我的是函数是" + myFunc.caller); } @@ -66,4 +66,4 @@ while (f) { <h2 id="浏览器兼容性">浏览器兼容性</h2> -<p>Function.caller目前被所有主流浏览器支持: Firefox, Safari, Chrome, Opera 和 IE. <a class="external" href="http://dl.dropbox.com/u/534786/callertest.html" title="http://dl.dropbox.com/u/534786/callertest.html"><span style="text-decoration: underline;">查看检测结果</span></a>.</p> +<p>Function.caller目前被所有主流浏览器支持: Firefox, Safari, Chrome, Opera 和 IE. <a class="external" href="http://dl.dropbox.com/u/534786/callertest.html" title="http://dl.dropbox.com/u/534786/callertest.html">查看检测结果</a>.</p> diff --git a/files/zh-cn/web/javascript/reference/global_objects/generator/index.html b/files/zh-cn/web/javascript/reference/global_objects/generator/index.html index 612024ca88..f7e4fc037b 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/generator/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/generator/index.html @@ -65,13 +65,13 @@ console.log(gen.next().value); <dl> <dt><code>Generator.prototype.next() </code>{{non-standard_inline}}</dt> - <dd>返回 {{jsxref("Operators/yield", "yield")}} 表达式产生的值. 与ES2015 生成器对象的<span style="font-family: courier,andale mono,monospace;">next()方法对应</span>.</dd> + <dd>返回 {{jsxref("Operators/yield", "yield")}} 表达式产生的值. 与ES2015 生成器对象的next()方法对应.</dd> <dt><code>Generator.prototype.close()</code> {{non-standard_inline}}</dt> - <dd>关闭生成器,因此执行该函数后调用<code>next()函数时将会抛出</code> {{jsxref("StopIteration")}} 错误. 与ES2015 生成器对象的<span style="font-family: courier,andale mono,monospace;">return()方法对应</span>..</dd> + <dd>关闭生成器,因此执行该函数后调用<code>next()函数时将会抛出</code> {{jsxref("StopIteration")}} 错误. 与ES2015 生成器对象的return()方法对应..</dd> <dt><code>Generator.prototype.send()</code> {{non-standard_inline}}</dt> <dd>用于将值发送到生成器。 该值由 {{jsxref("Operators/yield", "yield")}} 表达式返回, 并且返回下一个 {{jsxref("Operators/yield", "yield")}} 表达式产生的值. <code>send(x)</code> 对应于ES2015生成器对象中的 <code>next(x)</code></dd> <dt><strong><code>Generator.</code></strong><code>prototype.</code><strong><code>throw()</code> </strong> {{non-standard_inline}}</dt> - <dd>向生成器抛出错误. 与ES2015 生成器对象的<span style="font-family: courier,andale mono,monospace;">throw()方法对应</span>.</dd> + <dd>向生成器抛出错误. 与ES2015 生成器对象的throw()方法对应.</dd> </dl> <h3 id="旧生成器对象示例">旧生成器对象示例</h3> diff --git a/files/zh-cn/web/javascript/reference/global_objects/generator/throw/index.html b/files/zh-cn/web/javascript/reference/global_objects/generator/throw/index.html index 13138d5484..fec5b2f93c 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/generator/throw/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/generator/throw/index.html @@ -44,7 +44,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Generator/throw <h3 id="Example:_Using_test" name="Example:_Using_test">使用 <code>throw()</code></h3> -<p>下面的例子展示了一个简单的生成器并使用 <span style="font-family: courier,andale mono,monospace;">throw方法</span>向该生成器抛出一个异常,该异常通常可以通过 <code><a href="/en-US/docs/Web/JavaScript/Reference/Statements/try...catch">try...catch</a></code> 块进行捕获.</p> +<p>下面的例子展示了一个简单的生成器并使用 throw方法向该生成器抛出一个异常,该异常通常可以通过 <code><a href="/en-US/docs/Web/JavaScript/Reference/Statements/try...catch">try...catch</a></code> 块进行捕获.</p> <pre class="brush: js">function* gen() { while(true) { diff --git a/files/zh-cn/web/javascript/reference/global_objects/globalthis/index.html b/files/zh-cn/web/javascript/reference/global_objects/globalthis/index.html index e9c96e8656..e3c5d1b0a2 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/globalthis/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/globalthis/index.html @@ -14,7 +14,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/globalThis --- <div>{{jsSidebar("Objects")}}</div> -<p><span class="seoSummary">全局属性 <code>globalThis</code> 包含全局的 <code>this</code> 值,类似于全局对象(global object)。</span></p> +<p>全局属性 <code>globalThis</code> 包含全局的 <code>this</code> 值,类似于全局对象(global object)。</p> <div>{{EmbedInteractiveExample("pages/js/globalprops-globalthis.html","shorter")}}</div> diff --git a/files/zh-cn/web/javascript/reference/global_objects/index.html b/files/zh-cn/web/javascript/reference/global_objects/index.html index 293b4935b6..1ac71c0b32 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/index.html @@ -171,7 +171,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects <h3 id="国际化">国际化</h3> -<p><span class="tlid-translation translation" lang="zh-CN"><span title="">ECMAScript核心的附加功能,用于</span></span>支持多语言处理<span class="tlid-translation translation" lang="zh-CN"><span title="">。</span></span></p> +<p>ECMAScript核心的附加功能,用于支持多语言处理。</p> <div class="twocolumns"> <ul> diff --git a/files/zh-cn/web/javascript/reference/global_objects/infinity/index.html b/files/zh-cn/web/javascript/reference/global_objects/infinity/index.html index 7d8e6cb3c4..3181d4b7ff 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/infinity/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/infinity/index.html @@ -25,11 +25,11 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Infinity <h2 id="示例">示例</h2> -<pre class="brush: js line-numbers language-js notranslate"><code class="language-js">console<span class="punctuation token">.</span><span class="function token">log</span><span class="punctuation token">(</span><span class="number token">Infinity</span> <span class="punctuation token">)</span><span class="punctuation token">;</span> <span class="comment token">/* Infinity */</span> -console<span class="punctuation token">.</span><span class="function token">log</span><span class="punctuation token">(</span><span class="number token">Infinity</span> <span class="operator token">+</span> <span class="number token">1</span> <span class="punctuation token">)</span><span class="punctuation token">;</span> <span class="comment token">/* Infinity */</span> -console<span class="punctuation token">.</span><span class="function token">log</span><span class="punctuation token">(</span>Math<span class="punctuation token">.</span><span class="function token">pow</span><span class="punctuation token">(</span><span class="number token">10</span><span class="punctuation token">,</span> <span class="number token">1000</span><span class="punctuation token">)</span><span class="punctuation token">)</span><span class="punctuation token">;</span> <span class="comment token">/* Infinity */</span> -console<span class="punctuation token">.</span><span class="function token">log</span><span class="punctuation token">(</span>Math<span class="punctuation token">.</span><span class="function token">log</span><span class="punctuation token">(</span><span class="number token">0</span><span class="punctuation token">)</span> <span class="punctuation token">)</span><span class="punctuation token">;</span> <span class="comment token">/* -Infinity */</span> -console<span class="punctuation token">.</span><span class="function token">log</span><span class="punctuation token">(</span><span class="number token">1</span> <span class="operator token">/</span> <span class="number token">Infinity</span> <span class="punctuation token">)</span><span class="punctuation token">;</span> <span class="comment token">/* 0 */</span></code></pre> +<pre class="brush: js line-numbers language-js notranslate"><code class="language-js">console.log(Infinity ); /* Infinity */ +console.log(Infinity + 1 ); /* Infinity */ +console.log(Math.pow(10, 1000)); /* Infinity */ +console.log(Math.log(0) ); /* -Infinity */ +console.log(1 / Infinity ); /* 0 */</code></pre> <h2 id="规范">规范</h2> diff --git a/files/zh-cn/web/javascript/reference/global_objects/int32array/index.html b/files/zh-cn/web/javascript/reference/global_objects/int32array/index.html index 1e7ca21cc4..a1b8db6fc9 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/int32array/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/int32array/index.html @@ -195,7 +195,7 @@ var z = new Int32Array(buffer, 0, 4); <td>5.1</td> </tr> <tr> - <td><font face="consolas, Liberation Mono, courier, monospace"><span style="background-color: rgba(220, 220, 220, 0.5);">新</span></font> 的特性</td> + <td><font face="consolas, Liberation Mono, courier, monospace">新</font> 的特性</td> <td>{{CompatUnknown}}</td> <td>{{ CompatGeckoDesktop(44) }}</td> <td>{{CompatUnknown}}</td> diff --git a/files/zh-cn/web/javascript/reference/global_objects/internalerror/index.html b/files/zh-cn/web/javascript/reference/global_objects/internalerror/index.html index e0f98013f9..57f84f7db4 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/internalerror/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/internalerror/index.html @@ -65,7 +65,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/InternalError <h2 id="浏览器兼容性">浏览器兼容性</h2> -<h2 id="CompatibilityTable"><span style="font-size: 14px; font-weight: normal; line-height: 1.5;">{{CompatibilityTable}}</span></h2> +<h2 id="CompatibilityTable">{{CompatibilityTable}}</h2> <div id="compat-desktop"> <table class="compat-table"> diff --git a/files/zh-cn/web/javascript/reference/global_objects/intl/datetimeformat/index.html b/files/zh-cn/web/javascript/reference/global_objects/intl/datetimeformat/index.html index ef43816d44..eb886cb8b8 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/intl/datetimeformat/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/intl/datetimeformat/index.html @@ -154,7 +154,7 @@ console.log(new Intl.DateTimeFormat('ko-KR').format(date)); //大部分阿拉伯国家使用阿拉伯字母(real Arabic digits) console.log(new Intl.DateTimeFormat('ar-EG').format(date)); -// → "<span dir="rtl">٢٠/١٢/٢٠١٢</span>" +// → "٢٠/١٢/٢٠١٢" //在日本,应用可能想要使用日本日历, //2012 是平成24年(平成是是日本天皇明仁的年号,由1989年1月8日起开始计算直至现在) diff --git a/files/zh-cn/web/javascript/reference/global_objects/isfinite/index.html b/files/zh-cn/web/javascript/reference/global_objects/isfinite/index.html index b8f1c4d53c..296dcf5bc0 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/isfinite/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/isfinite/index.html @@ -33,15 +33,15 @@ translation_of: Web/JavaScript/Reference/Global_Objects/isFinite <h2 id="Examples" name="Examples" style="margin-bottom: 20px; line-height: 30px;">示例</h2> -<pre class="brush: js language-js" style="padding: 1em 0px 1em 30px; border-left-width: 6px; border-left-style: solid; font-family: Consolas, Monaco, 'Andale Mono', monospace; font-size: 14px; direction: ltr; white-space: normal; text-shadow: none; background-color: rgba(234, 239, 242, 0.247059);"><code class="language-js" style="font-family: Consolas, Monaco, 'Andale Mono', monospace; direction: ltr; white-space: pre; color: inherit; text-shadow: none;"><span class="function token">isFinite<span class="punctuation token" style="color: #999999;">(</span></span><span class="number token" style="color: #990055;">Infinity</span><span class="punctuation token" style="color: #999999;">)</span><span class="punctuation token" style="color: #999999;">;</span> <span class="comment token" style="color: #708090; display: inherit;"> // false -</span><span class="function token">isFinite<span class="punctuation token" style="color: #999999;">(</span></span><span class="number token" style="color: #990055;">NaN</span><span class="punctuation token" style="color: #999999;">)</span><span class="punctuation token" style="color: #999999;">;</span> <span class="comment token" style="color: #708090; display: inherit;"> // false -</span><span class="function token">isFinite<span class="punctuation token" style="color: #999999;">(</span></span><span class="operator token" style="background: rgba(255, 255, 255, 0.498039); color: #a67f59;">-</span><span class="number token" style="color: #990055;">Infinity</span><span class="punctuation token" style="color: #999999;">)</span><span class="punctuation token" style="color: #999999;">;</span><span class="comment token" style="color: #708090; display: inherit;"> // false -</span> -<span class="function token">isFinite<span class="punctuation token" style="color: #999999;">(</span></span><span class="number token" style="color: #990055;">0</span><span class="punctuation token" style="color: #999999;">)</span><span class="punctuation token" style="color: #999999;">;</span> <span class="comment token" style="color: #708090; display: inherit;"> // true -</span><span class="function token">isFinite<span class="punctuation token" style="color: #999999;">(</span></span><span class="number token" style="color: #990055;">2e64</span><span class="punctuation token" style="color: #999999;">)</span><span class="punctuation token" style="color: #999999;">;</span> <span class="comment token" style="color: #708090; display: inherit;"> // true, 在更强壮的Number.isFinite(null)中将会得到false -</span> - -<span class="function token">isFinite<span class="punctuation token" style="color: #999999;">(</span></span><span class="string token" style="color: #669900;">"0"</span><span class="punctuation token" style="color: #999999;">)</span><span class="punctuation token" style="color: #999999;">;</span> <span class="comment token" style="color: #708090; display: inherit;"> // true, 在更强壮的Number.isFinite('0')中将会得到false</span></code></pre> +<pre class="brush: js language-js" style="padding: 1em 0px 1em 30px; border-left-width: 6px; border-left-style: solid; font-family: Consolas, Monaco, 'Andale Mono', monospace; font-size: 14px; direction: ltr; white-space: normal; text-shadow: none; background-color: rgba(234, 239, 242, 0.247059);"><code class="language-js" style="font-family: Consolas, Monaco, 'Andale Mono', monospace; direction: ltr; white-space: pre; color: inherit; text-shadow: none;">isFinite(Infinity); // false +isFinite(NaN); // false +isFinite(-Infinity); // false + +isFinite(0); // true +isFinite(2e64); // true, 在更强壮的Number.isFinite(null)中将会得到false + + +isFinite("0"); // true, 在更强壮的Number.isFinite('0')中将会得到false</code></pre> <div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; line-height: inherit; top: 0px; background: 0px 0px;"> </div> diff --git a/files/zh-cn/web/javascript/reference/global_objects/isnan/index.html b/files/zh-cn/web/javascript/reference/global_objects/isnan/index.html index e9fd9ff613..772c25bc8e 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/isnan/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/isnan/index.html @@ -48,10 +48,10 @@ translation_of: Web/JavaScript/Reference/Global_Objects/isNaN <p>一个<code>isNaN</code>的 polyfill 可以理解为(这个polyfill利用了<code>NaN</code>自身永不相等于自身这一特征 ):</p> -<pre class="brush: js line-numbers language-js"><code class="language-js"><span class="keyword token">var</span> isNaN <span class="operator token">=</span> <span class="keyword token">function</span><span class="punctuation token">(</span>value<span class="punctuation token">)</span> <span class="punctuation token">{</span> - <span class="keyword token">var</span> n <span class="operator token">=</span> <span class="function token">Number</span><span class="punctuation token">(</span>value<span class="punctuation token">)</span><span class="punctuation token">;</span> - <span class="keyword token">return</span> n <span class="operator token">!==</span> n<span class="punctuation token">;</span> -<span class="punctuation token">}</span><span class="punctuation token">;</span></code></pre> +<pre class="brush: js line-numbers language-js"><code class="language-js">var isNaN = function(value) { + var n = Number(value); + return n !== n; +};</code></pre> <h2 id="Examples" name="Examples">示例</h2> diff --git a/files/zh-cn/web/javascript/reference/global_objects/json/index.html b/files/zh-cn/web/javascript/reference/global_objects/json/index.html index 81957d2e03..9eb0663504 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/json/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/json/index.html @@ -17,7 +17,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/JSON <h3 id="JavaScript_Object_Notation" name="JavaScript_Object_Notation">JavaScript Object Notation</h3> -<p><strong>JSON</strong> 是一种语法,用来序列化对象、数组、数值、字符串、布尔值和 {{jsxref("null")}} 。它基于 JavaScript 语法,但与之不同:<strong>JavaScript不是JSON,JSON也不是JavaScript</strong>。<span style="line-height: 1.5;">参考 </span><a href="http://timelessrepo.com/json-isnt-a-javascript-subset" style="line-height: 1.5; text-decoration: underline;">JSON:并不是JavaScript 的子集</a>。</p> +<p><strong>JSON</strong> 是一种语法,用来序列化对象、数组、数值、字符串、布尔值和 {{jsxref("null")}} 。它基于 JavaScript 语法,但与之不同:<strong>JavaScript不是JSON,JSON也不是JavaScript</strong>。参考 <a href="http://timelessrepo.com/json-isnt-a-javascript-subset" style="line-height: 1.5; text-decoration: underline;">JSON:并不是JavaScript 的子集</a>。</p> <table> <caption>JavaScript 与 JSON 的区别</caption> diff --git a/files/zh-cn/web/javascript/reference/global_objects/map/foreach/index.html b/files/zh-cn/web/javascript/reference/global_objects/map/foreach/index.html index 301214807e..76ef36556e 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/map/foreach/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/map/foreach/index.html @@ -14,7 +14,7 @@ browser-compat: javascript.builtins.Map.forEach --- <div>{{JSRef}}</div> -<p><span class="seoSummary"><code><strong>forEach()</strong></code> 方法按照插入顺序依次对 <code>Map</code> 中每个键/值对执行一次给定的函数</span></p> +<p><code><strong>forEach()</strong></code> 方法按照插入顺序依次对 <code>Map</code> 中每个键/值对执行一次给定的函数</p> <div>{{EmbedInteractiveExample("pages/js/map-prototype-foreach.html")}}</div> diff --git a/files/zh-cn/web/javascript/reference/global_objects/map/index.html b/files/zh-cn/web/javascript/reference/global_objects/map/index.html index 88ab546cf7..3a4c41dcdd 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/map/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/map/index.html @@ -157,7 +157,7 @@ myMap.get(function() {}); // undefined, 因为keyFunc !== function () {}</pre> <h3 id="将_NaN_作为_Map_的键">将 <code>NaN</code> 作为 <code>Map</code> 的键</h3> -<p><code>NaN</code> 也可以作为<code>Map</code>对象的键。虽然 <code>NaN</code> 和任何值甚至和自己都不相等(<code>NaN !== NaN</code> 返回true),但下面的例子表明,<code>NaN</code>作为Map的键来说是没有<span><span>区别的</span></span>:</p> +<p><code>NaN</code> 也可以作为<code>Map</code>对象的键。虽然 <code>NaN</code> 和任何值甚至和自己都不相等(<code>NaN !== NaN</code> 返回true),但下面的例子表明,<code>NaN</code>作为Map的键来说是没有区别的:</p> <pre class="brush: js">let myMap = new Map(); myMap.set(NaN, "not a number"); diff --git a/files/zh-cn/web/javascript/reference/global_objects/math/abs/index.html b/files/zh-cn/web/javascript/reference/global_objects/math/abs/index.html index 13f5f96b79..60747a871d 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/math/abs/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/math/abs/index.html @@ -22,7 +22,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Math/abs <h2 id="Description" name="Description">说明</h2> -<p><code><font face="Open Sans, sans-serif"><span style="line-height: 21px;">由于 </span></font>Math.abs()</code> <code>是</code> <code>Math</code> 中的一个静态方法,你应该通过 <code>Math.abs()</code> <code>调用。</code>(Math 不是构造器)</p> +<p><code><font face="Open Sans, sans-serif">由于 </font>Math.abs()</code> <code>是</code> <code>Math</code> 中的一个静态方法,你应该通过 <code>Math.abs()</code> <code>调用。</code>(Math 不是构造器)</p> <h2 id="Examples" name="Examples">示例</h2> diff --git a/files/zh-cn/web/javascript/reference/global_objects/math/cbrt/index.html b/files/zh-cn/web/javascript/reference/global_objects/math/cbrt/index.html index d583caf717..96d8b00a37 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/math/cbrt/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/math/cbrt/index.html @@ -34,7 +34,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Math/cbrt <p>而不是作为您创建的Math对象的方法(Math不是构造函数)。</p> -<p><span style="font-family: 'Courier New','Andale Mono',monospace; font-weight: inherit; line-height: normal;">cbrt 是 "cube root" 的缩写, 意思是立方根.</span></p> +<p>cbrt 是 "cube root" 的缩写, 意思是立方根.</p> <h2 id="Examples" name="Examples">示例</h2> @@ -50,7 +50,7 @@ Math.cbrt(Infinity); // Infinity Math.cbrt(null); // 0 Math.cbrt(2); // 1.2599210498948734</pre> -<h2 id="Polyfill"><font face="consolas, Liberation Mono, courier, monospace"><span style="background-color: rgba(220, 220, 220, 0.5);">Polyfill</span></font></h2> +<h2 id="Polyfill"><font face="consolas, Liberation Mono, courier, monospace">Polyfill</font></h2> <p>为了与旧版浏览器兼容, 可使用下方函数模拟cbrt():</p> diff --git a/files/zh-cn/web/javascript/reference/global_objects/math/clz32/index.html b/files/zh-cn/web/javascript/reference/global_objects/math/clz32/index.html index ec23e5ab09..bd41c06b44 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/math/clz32/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/math/clz32/index.html @@ -31,7 +31,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Math/clz32 <p><code>NaN</code>, <code>Infinity</code>,<code> -Infinity</code> 这三个数字转成 32 位无符号整形数字后都是 <code>0</code>.</p> -<p><span>这个函数主要用于那些编译目标为 JS 语言的系统中, 比如 Emscripten.</span></p> +<p>这个函数主要用于那些编译目标为 JS 语言的系统中, 比如 Emscripten.</p> <h2 id="示例">示例</h2> diff --git a/files/zh-cn/web/javascript/reference/global_objects/math/expm1/index.html b/files/zh-cn/web/javascript/reference/global_objects/math/expm1/index.html index 74502e9d83..f7baeb0486 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/math/expm1/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/math/expm1/index.html @@ -22,7 +22,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Math/expm1 <h2 id="Description" name="Description">描述</h2> -<p><code><span style="color: #4d4e53; font-family: 'Open Sans',sans-serif; line-height: 21px;">参数 </span><code style="font-size: 14px; line-height: inherit; margin: 0px; padding: 0px; border: 0px; color: rgb(77, 78, 83);">x</code><span style="color: #4d4e53; font-family: 'Open Sans',sans-serif; line-height: 21px;"> 会被自动类型转换成 </span><code style="font-size: 14px; line-height: inherit; margin: 0px; padding: 0px; border: 0px; color: rgb(77, 78, 83);">number </code><span style="color: #4d4e53; font-family: 'Open Sans',sans-serif; line-height: 21px;">类型.</span></code></p> +<p><code>参数 <code style="font-size: 14px; line-height: inherit; margin: 0px; padding: 0px; border: 0px; color: rgb(77, 78, 83);">x</code> 会被自动类型转换成 <code style="font-size: 14px; line-height: inherit; margin: 0px; padding: 0px; border: 0px; color: rgb(77, 78, 83);">number </code>类型.</code></p> <p><code>expm1 是 "exponent minus 1" 的缩写.</code></p> diff --git a/files/zh-cn/web/javascript/reference/global_objects/math/floor/index.html b/files/zh-cn/web/javascript/reference/global_objects/math/floor/index.html index 91e6f0c395..530f15a033 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/math/floor/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/math/floor/index.html @@ -146,7 +146,7 @@ Math.ceil10(-59, 1); // -50 <td></td> </tr> <tr> - <td>{{SpecName('ES6', '#sec-math.floor', 'Math.floor')}}<span class="hidden"> </span></td> + <td>{{SpecName('ES6', '#sec-math.floor', 'Math.floor')}} </td> <td>{{Spec2('ES6')}}</td> <td></td> </tr> diff --git a/files/zh-cn/web/javascript/reference/global_objects/math/imul/index.html b/files/zh-cn/web/javascript/reference/global_objects/math/imul/index.html index 67da70040d..9d0e9f1c29 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/math/imul/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/math/imul/index.html @@ -45,7 +45,7 @@ Math.imul(0xfffffffe, 5) //-10 <p>下面的 JavaScript 代码可以实现该函数:</p> -<pre class="brush: js"><span style='background-color: transparent; font-family: consolas,"Liberation Mono",courier,monospace; font-size: 1rem; font-weight: inherit; letter-spacing: -0.00278rem; white-space: pre;'>if (!Math.imul) Math.imul = function(a, b) {</span> +<pre class="brush: js">if (!Math.imul) Math.imul = function(a, b) { var aHi = (a >>> 16) & 0xffff; var aLo = a & 0xffff; var bHi = (b >>> 16) & 0xffff; @@ -57,7 +57,7 @@ Math.imul(0xfffffffe, 5) //-10 <p>然而,下面的实现性能会更好一些。因为运行这段 polyfill 的浏览器很有可能会在内部使用浮点数,而不是整数表示 javascript 的 Number。</p> -<pre class="brush: js"><span style='background-color: transparent; font-family: consolas,"Liberation Mono",courier,monospace; font-size: 1rem; font-weight: inherit; letter-spacing: -0.00278rem; white-space: pre;'>if (!Math.imul) Math.imul = function(opA, opB) {</span> +<pre class="brush: js">if (!Math.imul) Math.imul = function(opA, opB) { opB |= 0; // ensure that opB is an integer. opA will automatically be coerced. // floating points give us 53 bits of precision to work with plus 1 sign bit // automatically handled for our convienence: diff --git a/files/zh-cn/web/javascript/reference/global_objects/math/log10/index.html b/files/zh-cn/web/javascript/reference/global_objects/math/log10/index.html index 7819f922e8..3b8aefc6ed 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/math/log10/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/math/log10/index.html @@ -9,7 +9,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Math/log10 <h2 id="Summary" name="Summary">概述</h2> -<p><code><strong>Math.log10()</strong></code> 函数返回<span style="color: #4d4e53; line-height: 1.5;">一个数字以 10 为底的对数.</span></p> +<p><code><strong>Math.log10()</strong></code> 函数返回一个数字以 10 为底的对数.</p> <h2 id="Syntax" name="Syntax">语法</h2> diff --git a/files/zh-cn/web/javascript/reference/global_objects/math/pi/index.html b/files/zh-cn/web/javascript/reference/global_objects/math/pi/index.html index 77f373196e..69b5ab79d1 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/math/pi/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/math/pi/index.html @@ -23,11 +23,11 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Math/PI <p>下面的函数使用 Math.PI 计算给定半径的圆周长:</p> -<pre class="brush:js language-js" style="padding: 1em 0px 1em 30px; font-size: 14px; white-space: normal; color: rgb(77, 78, 83);"><code class="language-js" style="direction: ltr; white-space: pre;"><span class="keyword token" style="color: rgb(0, 119, 170);">function</span> calculateCircumference <span class="punctuation token" style="color: rgb(153, 153, 153);">(</span>radius<span class="punctuation token" style="color: rgb(153, 153, 153);">)</span> <span class="punctuation token" style="color: rgb(153, 153, 153);">{</span> - <span class="keyword token" style="color: rgb(0, 119, 170);">return</span> <span class="number token" style="color: rgb(153, 0, 85);">2</span> <span class="operator token" style="background: rgba(255, 255, 255, 0.498039); color: rgb(166, 127, 89);">*</span> Math<span class="punctuation token" style="color: rgb(153, 153, 153);">.</span>PI <span class="operator token" style="background: rgba(255, 255, 255, 0.498039); color: rgb(166, 127, 89);">*</span> radius<span class="punctuation token" style="color: rgb(153, 153, 153);">;</span> -<span class="punctuation token" style="color: rgb(153, 153, 153);">}</span> +<pre class="brush:js language-js" style="padding: 1em 0px 1em 30px; font-size: 14px; white-space: normal; color: rgb(77, 78, 83);"><code class="language-js" style="direction: ltr; white-space: pre;">function calculateCircumference (radius) { + return 2 * Math.PI * radius; +} -<span class="function token" style="color: rgb(221, 74, 104);">calculateCircumference<span class="punctuation token" style="color: rgb(153, 153, 153);">(</span></span><span class="number token" style="color: rgb(153, 0, 85);">1</span><span class="punctuation token" style="color: rgb(153, 153, 153);">)</span><span class="punctuation token" style="color: rgb(153, 153, 153);">;</span> <span class="comment token" style="color: rgb(112, 128, 144);"> // 6.283185307179586</span></code></pre> +calculateCircumference(1); // 6.283185307179586</code></pre> <h2 id="规范">规范</h2> diff --git a/files/zh-cn/web/javascript/reference/global_objects/math/pow/index.html b/files/zh-cn/web/javascript/reference/global_objects/math/pow/index.html index 32489252c0..3ede0647ac 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/math/pow/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/math/pow/index.html @@ -5,7 +5,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Math/pow --- <div>{{JSRef}}</div> -<p><code><strong>Math.pow()</strong></code> 函数返回基数(<code>base</code>)的指数(<code>exponent</code>)次幂,即<span style="line-height: 1.572;"> </span><code style="font-size: 14px;">base<sup>exponent</sup></code><span style="line-height: 1.572;">。</span></p> +<p><code><strong>Math.pow()</strong></code> 函数返回基数(<code>base</code>)的指数(<code>exponent</code>)次幂,即 <code style="font-size: 14px;">base<sup>exponent</sup></code>。</p> <p>{{EmbedInteractiveExample("pages/js/math-pow.html")}}</p> diff --git a/files/zh-cn/web/javascript/reference/global_objects/math/random/index.html b/files/zh-cn/web/javascript/reference/global_objects/math/random/index.html index efc11b6894..e25608ec05 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/math/random/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/math/random/index.html @@ -50,11 +50,11 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Math/random <p>这个例子返回了一个在指定值之间的随机整数。这个值不小于 <code>min</code> (如果 <code>min</code> 不是整数,则不小于 <code>min</code> 的向上取整数),且小于(不等于)<code>max</code>。</p> -<pre class="brush: js line-numbers language-js notranslate"><code class="language-js"><span class="keyword token">function</span> <span class="function token">getRandomInt</span><span class="punctuation token">(</span>min<span class="punctuation token">,</span> max<span class="punctuation token">)</span> <span class="punctuation token">{</span> - min <span class="operator token">=</span> Math<span class="punctuation token">.</span><span class="function token">ceil</span><span class="punctuation token">(</span>min<span class="punctuation token">)</span><span class="punctuation token">;</span> - max <span class="operator token">=</span> Math<span class="punctuation token">.</span><span class="function token">floor</span><span class="punctuation token">(</span>max<span class="punctuation token">)</span><span class="punctuation token">;</span> - <span class="keyword token">return</span> Math<span class="punctuation token">.</span><span class="function token">floor</span><span class="punctuation token">(</span>Math<span class="punctuation token">.</span><span class="function token">random</span><span class="punctuation token">(</span><span class="punctuation token">)</span> <span class="operator token">*</span> <span class="punctuation token">(</span>max <span class="operator token">-</span> min<span class="punctuation token">)</span><span class="punctuation token">)</span> <span class="operator token">+</span> min<span class="punctuation token">;</span> </code>//不含最大值,含最小值<code class="language-js"> -<span class="punctuation token">}</span></code></pre> +<pre class="brush: js line-numbers language-js notranslate"><code class="language-js">function getRandomInt(min, max) { + min = Math.ceil(min); + max = Math.floor(max); + return Math.floor(Math.random() * (max - min)) + min; </code>//不含最大值,含最小值<code class="language-js"> +}</code></pre> <div class="note"> <p>也许很容易想到用 <code>Math.round()</code> 来实现,但是这会导致你的随机数处于一个不均匀的分布,这可能不符合你的需求。</p> @@ -64,11 +64,11 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Math/random <p>上一个例子提到的函数 <code>getRandomInt()</code> 结果范围包含了最小值,但不含最大值。如果你的随机结果需要同时包含最小值和最大值,怎么办呢? <code>getRandomIntInclusive()</code> 函数可以实现。</p> -<pre class="brush: js line-numbers language-js notranslate"><code class="language-js"><span class="keyword token">function</span> <span class="function token">getRandomIntInclusive</span><span class="punctuation token">(</span>min<span class="punctuation token">,</span> max<span class="punctuation token">)</span> <span class="punctuation token">{</span> - min <span class="operator token">=</span> Math<span class="punctuation token">.</span><span class="function token">ceil</span><span class="punctuation token">(</span>min<span class="punctuation token">)</span><span class="punctuation token">;</span> - max <span class="operator token">=</span> Math<span class="punctuation token">.</span><span class="function token">floor</span><span class="punctuation token">(</span>max<span class="punctuation token">)</span><span class="punctuation token">;</span> - <span class="keyword token">return</span> Math<span class="punctuation token">.</span><span class="function token">floor</span><span class="punctuation token">(</span>Math<span class="punctuation token">.</span><span class="function token">random</span><span class="punctuation token">(</span><span class="punctuation token">)</span> <span class="operator token">*</span> <span class="punctuation token">(</span>max <span class="operator token">-</span> min <span class="operator token">+</span> <span class="number token">1</span><span class="punctuation token">)</span><span class="punctuation token">)</span> <span class="operator token">+</span> min<span class="punctuation token">;</span> <span class="comment token">//含最大值,含最小值 </span> -<span class="punctuation token">}</span></code></pre> +<pre class="brush: js line-numbers language-js notranslate"><code class="language-js">function getRandomIntInclusive(min, max) { + min = Math.ceil(min); + max = Math.floor(max); + return Math.floor(Math.random() * (max - min + 1)) + min; //含最大值,含最小值 +}</code></pre> <h2 id="规范">规范</h2> diff --git a/files/zh-cn/web/javascript/reference/global_objects/math/sign/index.html b/files/zh-cn/web/javascript/reference/global_objects/math/sign/index.html index ca7678c9f0..9c41082511 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/math/sign/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/math/sign/index.html @@ -50,12 +50,12 @@ Math.sign(); // NaN <h2 id="Compatibility" name="Compatibility">Polyfill</h2> -<pre class="brush: js language-js"><code class="language-js"><span class="keyword token">function</span> <span class="function token">sign<span class="punctuation token">(</span></span>x<span class="punctuation token">)</span> <span class="punctuation token">{</span> - x <span class="operator token">=</span> <span class="operator token">+</span>x<span class="comment token"> ;// convert to a number -</span> <span class="keyword token">if</span> <span class="punctuation token">(</span>x <span class="operator token">===</span> <span class="number token">0</span> <span class="operator token">||</span> <span class="function token">isNaN<span class="punctuation token">(</span></span>x<span class="punctuation token">)</span><span class="punctuation token">)</span> - <span class="keyword token">return</span> x; - <span class="keyword token">return</span> x <span class="operator token">></span> <span class="number token">0</span> <span class="operator token">?</span> <span class="number token">1</span> <span class="punctuation token">:</span> <span class="operator token">-</span><span class="number token">1;</span> -<span class="punctuation token">}</span></code></pre> +<pre class="brush: js language-js"><code class="language-js">function sign(x) { + x = +x ;// convert to a number + if (x === 0 || isNaN(x)) + return x; + return x > 0 ? 1 : -1; +}</code></pre> <p> </p> diff --git a/files/zh-cn/web/javascript/reference/global_objects/object/__definegetter__/index.html b/files/zh-cn/web/javascript/reference/global_objects/object/__definegetter__/index.html index 28773a6bc8..a9c388d009 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/object/__definegetter__/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/object/__definegetter__/index.html @@ -22,7 +22,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Object/__defineGetter__ </dl> <h2 id="Description" name="Description">描述</h2> <p><code>__defineGetter__ 方法可以为一个已经存在的对象设置(新建或修改)访问器属性,</code>而 {{jsxref("Operators/get", "对象字面量中的 get 语法", "", 1)}} 只能在新建一个对象时使用。</p> -<h2 id="Examples" name="Examples"><span class="def"><span>示例</span></span></h2> +<h2 id="Examples" name="Examples">示例</h2> <pre class="brush: js">// 请注意,该方法是非标准的: var o = {}; diff --git a/files/zh-cn/web/javascript/reference/global_objects/object/__definesetter__/index.html b/files/zh-cn/web/javascript/reference/global_objects/object/__definesetter__/index.html index 81a159b69f..4c9dce1dd4 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/object/__definesetter__/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/object/__definesetter__/index.html @@ -5,7 +5,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Object/__defineSetter__ --- <div> {{JSRef("Global_Objects", "Object")}} {{non-standard_header}} {{deprecated_header}}</div> -<h2 id="Summary" name="Summary"><span class="def"><span>概述</span></span></h2> +<h2 id="Summary" name="Summary">概述</h2> <p><code><strong>__defineSetter__ </strong>方法可以将一个函数绑定在当前对象的指定属性</code>上,当那个属性被赋值时,你所绑定的函数就会被调用。</p> <h2 id="Syntax" name="Syntax">语法</h2> <pre class="syntaxbox"><code><var>obj</var>.__defineSetter__(<var>prop</var>, <var>fun</var>)</code></pre> @@ -32,7 +32,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Object/__defineSetter__ <p><code>__defineSetter__</code> 方法可以为一个已经存在的对象设置(新建或修改)访问器属性,而 {{jsxref("Operators/set", "对象字面量中的 set 语法", "", 1)}} 只能在新建一个对象时使用。</p> <h2 id="Specifications" name="Specifications">规范</h2> <p>不属于任何规范。</p> -<h2 id="Browser_compatibility" name="Browser_compatibility"><span class="def"><span>浏览器兼容性</span></span></h2> +<h2 id="Browser_compatibility" name="Browser_compatibility">浏览器兼容性</h2> <div> {{CompatibilityTable}}</div> <div id="compat-desktop"> diff --git a/files/zh-cn/web/javascript/reference/global_objects/object/create/index.html b/files/zh-cn/web/javascript/reference/global_objects/object/create/index.html index a9b54f733d..073605d77f 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/object/create/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/object/create/index.html @@ -75,7 +75,7 @@ console.log('Is rect an instance of Shape?', rect instanceof Shape); // true rect.move(1, 1); // Outputs, 'Shape moved.'</pre> -<p>如果你希望能继承到多个对象,则可以使用<span class="short_text" id="result_box" lang="zh-CN"><span>混入的方式。</span></span></p> +<p>如果你希望能继承到多个对象,则可以使用混入的方式。</p> <pre class="brush: js notranslate">function MyClass() { SuperClass.call(this); diff --git a/files/zh-cn/web/javascript/reference/global_objects/object/defineproperty/index.html b/files/zh-cn/web/javascript/reference/global_objects/object/defineproperty/index.html index beaca31a6a..c711f8b4d5 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/object/defineproperty/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/object/defineproperty/index.html @@ -88,7 +88,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Object/defineProperty <h4 id="描述符默认值汇总">描述符默认值汇总</h4> <ul> - <li>拥有布尔值的键 <code>configurable</code>、<code>enumerable</code> 和 <code>writable</code> 的默认值都是 <span style="font-family: courier new,andale mono,monospace; line-height: 1.5;"><code>false</code></span>。</li> + <li>拥有布尔值的键 <code>configurable</code>、<code>enumerable</code> 和 <code>writable</code> 的默认值都是 <code>false</code>。</li> <li>属性值和函数的键 <code>value</code>、<code>get</code> 和 <code>set</code> 字段的默认值为 <code>undefined</code>。</li> </ul> @@ -172,11 +172,11 @@ Object.defineProperty(obj, "key", withValue("static")); <h2 id="示例">示例</h2> -<p>如果你想了解如何使用 <code>Object.defineProperty</code> 方法和<em>类二进制标记</em>语法<span style="line-height: 1.5;">,可以看看</span>这些<a href="/en-US/docs/JavaScript/Reference/Global_Objects/Object/defineProperty/Additional_examples" style="line-height: 1.5;">额外示例</a><span style="line-height: 1.5;">。</span></p> +<p>如果你想了解如何使用 <code>Object.defineProperty</code> 方法和<em>类二进制标记</em>语法,可以看看这些<a href="/en-US/docs/JavaScript/Reference/Global_Objects/Object/defineProperty/Additional_examples" style="line-height: 1.5;">额外示例</a>。</p> <h3 id="创建属性">创建属性</h3> -<p>如果对象中不存在指定的属性,<span style="font-family: courier new,andale mono,monospace; line-height: 1.5;"><code>Object.defineProperty()</code></span> 会创建这个属性。当描述符中省略某些字段时,这些字段将使用它们的默认值。</p> +<p>如果对象中不存在指定的属性,<code>Object.defineProperty()</code> 会创建这个属性。当描述符中省略某些字段时,这些字段将使用它们的默认值。</p> <pre class="brush: js notranslate">var o = {}; // 创建一个新对象 diff --git a/files/zh-cn/web/javascript/reference/global_objects/object/getownpropertydescriptors/index.html b/files/zh-cn/web/javascript/reference/global_objects/object/getownpropertydescriptors/index.html index f07f3bfa33..ebce4498fa 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/object/getownpropertydescriptors/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/object/getownpropertydescriptors/index.html @@ -41,14 +41,14 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDes <p>创建子类的典型方法是定义子类,将其原型设置为超类的实例,然后在该实例上定义属性。这么写很不优雅,特别是对于 getters 和 setter 而言。 相反,您可以使用此代码设置原型:</p> -<pre class="brush: js line-numbers language-js"><code class="language-js"><span class="keyword token">function</span> <span class="function token">superclass</span><span class="punctuation token">(</span><span class="punctuation token">)</span> <span class="punctuation token">{</span><span class="punctuation token">}</span> -superclass<span class="punctuation token">.</span>prototype <span class="operator token">=</span> <span class="punctuation token">{</span> - <span class="comment token">// 在这里定义方法和属性</span> -<span class="punctuation token">}</span><span class="punctuation token">;</span> -<span class="keyword token">function</span> <span class="function token">subclass</span><span class="punctuation token">(</span><span class="punctuation token">)</span> <span class="punctuation token">{</span><span class="punctuation token">}</span> -subclass<span class="punctuation token">.</span>prototype <span class="operator token">=</span> Object<span class="punctuation token">.</span><span class="function token">create</span><span class="punctuation token">(</span>superclass<span class="punctuation token">.</span>prototype<span class="punctuation token">,</span> Object<span class="punctuation token">.</span><span class="function token">getOwnPropertyDescriptors</span><span class="punctuation token">(</span><span class="punctuation token">{</span> - <span class="comment token">// 在这里定义方法和属性</span> -<span class="punctuation token">}</span><span class="punctuation token">)</span><span class="punctuation token">)</span><span class="punctuation token">;</span></code></pre> +<pre class="brush: js line-numbers language-js"><code class="language-js">function superclass() {} +superclass.prototype = { + // 在这里定义方法和属性 +}; +function subclass() {} +subclass.prototype = Object.create(superclass.prototype, Object.getOwnPropertyDescriptors({ + // 在这里定义方法和属性 +}));</code></pre> <h2 id="规范">规范</h2> diff --git a/files/zh-cn/web/javascript/reference/global_objects/object/is/index.html b/files/zh-cn/web/javascript/reference/global_objects/object/is/index.html index 860a49d231..f9f8f0a2fd 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/object/is/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/object/is/index.html @@ -14,7 +14,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Object/is <p><code><strong>Object.is()</strong></code> 方法判断两个值是否为<a href="/zh-CN/docs/Web/JavaScript/Equality_comparisons_and_sameness">同一个值</a>。</p> -<p><font face="x-locale-heading-primary, zillaslab, Palatino, Palatino Linotype, x-locale-heading-secondary, serif"><span style="font-size: 37.33327865600586px;"><strong>语法</strong></span></font></p> +<p><font face="x-locale-heading-primary, zillaslab, Palatino, Palatino Linotype, x-locale-heading-secondary, serif"><strong>语法</strong></font></p> <p> </p><pre class="syntaxbox notranslate"><code>Object.is(<var>value1</var>, <var>value2</var>);</code></pre> @@ -119,7 +119,7 @@ Object.is(-0, -0); // true Object.is(NaN, 0/0); // true </pre> -<p><font face="x-locale-heading-primary, zillaslab, Palatino, Palatino Linotype, x-locale-heading-secondary, serif"><span style="font-size: 37.33327865600586px;"><strong>规范</strong></span></font></p> +<p><font face="x-locale-heading-primary, zillaslab, Palatino, Palatino Linotype, x-locale-heading-secondary, serif"><strong>规范</strong></font></p> <p> </p><table> diff --git a/files/zh-cn/web/javascript/reference/global_objects/object/setprototypeof/index.html b/files/zh-cn/web/javascript/reference/global_objects/object/setprototypeof/index.html index 79ab23e2b6..0bc82c3e09 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/object/setprototypeof/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/object/setprototypeof/index.html @@ -49,7 +49,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Object/setPrototypeOf <h2 id="Notes" name="Notes">Polyfill</h2> -<p><span class="short_text" id="result_box" lang="en"><span>我们必须借助非标准的</span> </span> </p> +<p>我们必须借助非标准的 </p> <p>使用较旧的 {{jsxref("Object.prototype.__proto__")}} 属性,我们可以很容易地定义Object.setPrototypeOf 如果它不可用:</p> diff --git a/files/zh-cn/web/javascript/reference/global_objects/object/tosource/index.html b/files/zh-cn/web/javascript/reference/global_objects/object/tosource/index.html index 23d070b86a..e609077520 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/object/tosource/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/object/tosource/index.html @@ -73,7 +73,7 @@ alert(new Person("Joe").toSource()); // ---> new Person("Joe")</pre> <h3 id="循环引用限制">循环引用限制</h3> -<p><span id="noHighlight_0.3266603437527873">对于包含对自身的引用的对象 (例如, 循环链表或可以遍历两种方式的树), </span><code>toSource()</code><span>不会重新创建自引用, 如火狐24。例如:</span></p> +<p>对于包含对自身的引用的对象 (例如, 循环链表或可以遍历两种方式的树), <code>toSource()</code>不会重新创建自引用, 如火狐24。例如:</p> <pre class="brush: js">var obj1 = {}; var obj2 = { a: obj1 }; @@ -87,7 +87,7 @@ obj1 = eval(objSource); console.log('Cyclical: ' + (obj1.b.a == obj1));</pre> -<p><span id="noHighlight_0.30716570898096807">如果使用循环结构, 并且需要 </span><code>toSource()</code><span>, 则对象必须提供对 </span><code>toSource()</code><span> 的重写, 无论是对构造函数的引用还是提供匿名函数。</span></p> +<p>如果使用循环结构, 并且需要 <code>toSource()</code>, 则对象必须提供对 <code>toSource()</code> 的重写, 无论是对构造函数的引用还是提供匿名函数。</p> <h2 id="Examples" name="Examples">示例</h2> diff --git a/files/zh-cn/web/javascript/reference/global_objects/object/tostring/index.html b/files/zh-cn/web/javascript/reference/global_objects/object/tostring/index.html index 7ff9cdb557..55310e85b0 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/object/tostring/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/object/tostring/index.html @@ -41,7 +41,7 @@ o.toString(); // 返回 [object Object] <h3 id="覆盖默认的_toString_方法">覆盖默认的 <code>toString</code> 方法</h3> -<p>可以自定义一个方法,来取代默认的 <code>toString()</code> 方法。该 <code>toString()</code> 方法不能传入参数,并且必须返回一个字符串。自定义的 <code>toString()</code><span> 方法可以是任何我们需要的值,但如果它附带有关对象的信息,它将变得非常有用。</span></p> +<p>可以自定义一个方法,来取代默认的 <code>toString()</code> 方法。该 <code>toString()</code> 方法不能传入参数,并且必须返回一个字符串。自定义的 <code>toString()</code> 方法可以是任何我们需要的值,但如果它附带有关对象的信息,它将变得非常有用。</p> <p>以下代码定义了 <code>Dog</code> 对象类型,并创建了一个 <code>Dog</code> 类型的 <code>theDog</code> 对象:</p> diff --git a/files/zh-cn/web/javascript/reference/global_objects/object/valueof/index.html b/files/zh-cn/web/javascript/reference/global_objects/object/valueof/index.html index 1d732df222..c9f98bebc4 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/object/valueof/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/object/valueof/index.html @@ -149,16 +149,16 @@ console.log( str2.valueOf() === str2 ); // false</pre> <h3 id="改写_.prototype.valueof">改写 .prototype.valueof</h3> -<pre class="brush: js line-numbers language-js"><code class="language-js"><span class="keyword token">function</span> <span class="function token">MyNumberType</span><span class="punctuation token">(</span>n<span class="punctuation token">)</span> <span class="punctuation token">{</span> - <span class="keyword token">this</span><span class="punctuation token">.</span>number <span class="operator token">=</span> n<span class="punctuation token">;</span> -<span class="punctuation token">}</span> +<pre class="brush: js line-numbers language-js"><code class="language-js">function MyNumberType(n) { + this.number = n; +} -MyNumberType<span class="punctuation token">.</span>prototype<span class="punctuation token">.</span>valueOf <span class="operator token">=</span> <span class="keyword token">function</span><span class="punctuation token">(</span><span class="punctuation token">)</span> <span class="punctuation token">{</span> - <span class="keyword token">return</span> <span class="keyword token">this</span><span class="punctuation token">.</span>number<span class="punctuation token">;</span> -<span class="punctuation token">}</span><span class="punctuation token">;</span> +MyNumberType.prototype.valueOf = function() { + return this.number; +}; -<span class="keyword token">var</span> myObj <span class="operator token">=</span> <span class="keyword token">new</span> <span class="class-name token">MyNumberType</span><span class="punctuation token">(</span><span class="number token">4</span><span class="punctuation token">)</span><span class="punctuation token">;</span> -myObj <span class="operator token">+</span> <span class="number token">3</span><span class="punctuation token">;</span> <span class="comment token">// 7</span></code></pre> +var myObj = new MyNumberType(4); +myObj + 3; // 7</code></pre> <h2 id="规范">规范</h2> diff --git a/files/zh-cn/web/javascript/reference/global_objects/object/values/index.html b/files/zh-cn/web/javascript/reference/global_objects/object/values/index.html index c2d4cc3526..d744ebcb13 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/object/values/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/object/values/index.html @@ -57,7 +57,7 @@ console.log(Object.values('foo')); // ['f', 'o', 'o']</pre> <h2 id="Polyfill">Polyfill </h2> -<p><code><font face="Open Sans, arial, x-locale-body, sans-serif"><span style="background-color: #ffffff;">如果要 </span></font>Object.values</code>兼容不支持它的旧环境,可在<font face="consolas, Liberation Mono, courier, monospace"><span style="background-color: #eeeeee;"> </span></font><a href="https://github.com/tc39/proposal-object-values-entries">tc39/proposal-object-values-entries</a> 或 <a href="https://github.com/es-shims/Object.values">es-shims/Object.values</a> 中找到 Polyfill 。</p> +<p><code><font face="Open Sans, arial, x-locale-body, sans-serif">如果要 </font>Object.values</code>兼容不支持它的旧环境,可在<font face="consolas, Liberation Mono, courier, monospace"> </font><a href="https://github.com/tc39/proposal-object-values-entries">tc39/proposal-object-values-entries</a> 或 <a href="https://github.com/es-shims/Object.values">es-shims/Object.values</a> 中找到 Polyfill 。</p> <p>根据<strong>Object.keys()</strong>的Polyfill仿写一个:</p> diff --git a/files/zh-cn/web/javascript/reference/global_objects/parsefloat/index.html b/files/zh-cn/web/javascript/reference/global_objects/parsefloat/index.html index 6469340da8..21d4e0bfbd 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/parsefloat/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/parsefloat/index.html @@ -55,13 +55,13 @@ translation_of: Web/JavaScript/Reference/Global_Objects/parseFloat <p>下面的例子都返回<strong>3.14</strong></p> -<pre class="brush: js line-numbers language-js"><code class="language-js"><span class="function token">parseFloat</span><span class="punctuation token">(</span><span class="number token">3.14</span><span class="punctuation token">)</span><span class="punctuation token">;</span> -<span class="function token">parseFloat</span><span class="punctuation token">(</span><span class="string token">'3.14'</span><span class="punctuation token">)</span><span class="punctuation token">;</span> -<span class="function token">parseFloat</span><span class="punctuation token">(</span><span class="string token">' 3.14 '</span><span class="punctuation token">)</span><span class="punctuation token">;</span> -<span class="function token">parseFloat</span><span class="punctuation token">(</span><span class="string token">'314e-2'</span><span class="punctuation token">)</span><span class="punctuation token">;</span> -<span class="function token">parseFloat</span><span class="punctuation token">(</span><span class="string token">'0.0314E+2'</span><span class="punctuation token">)</span><span class="punctuation token">;</span> -<span class="function token">parseFloat</span><span class="punctuation token">(</span><span class="string token">'3.14some non-digit characters'</span><span class="punctuation token">)</span><span class="punctuation token">;</span> -<span class="function token">parseFloat</span><span class="punctuation token">(</span><span class="punctuation token">{</span> <span class="function function-variable token">toString</span><span class="punctuation token">:</span> <span class="keyword token">function</span><span class="punctuation token">(</span><span class="punctuation token">)</span> <span class="punctuation token">{</span> <span class="keyword token">return</span> <span class="string token">"3.14"</span> <span class="punctuation token">}</span> <span class="punctuation token">}</span><span class="punctuation token">)</span><span class="punctuation token">;</span></code></pre> +<pre class="brush: js line-numbers language-js"><code class="language-js">parseFloat(3.14); +parseFloat('3.14'); +parseFloat(' 3.14 '); +parseFloat('314e-2'); +parseFloat('0.0314E+2'); +parseFloat('3.14some non-digit characters'); +parseFloat({ toString: function() { return "3.14" } });</code></pre> <h3 id="parseFloat返回NaN"><code>parseFloat</code>返回NaN</h3> @@ -74,8 +74,8 @@ translation_of: Web/JavaScript/Reference/Global_Objects/parseFloat <p>以下例子均返回 <code>900719925474099300</code>,当整数太大以至于不能被转换时将失去精度。</p> -<pre class="brush: js line-numbers language-js"><code class="language-js"><span class="function token">parseFloat</span><span class="punctuation token">(</span><span class="number token">900719925474099267n</span><span class="punctuation token">)</span><span class="punctuation token">;</span> -<span class="function token">parseFloat</span><span class="punctuation token">(</span><span class="string token">'900719925474099267n'</span><span class="punctuation token">)</span><span class="punctuation token">;</span></code></pre> +<pre class="brush: js line-numbers language-js"><code class="language-js">parseFloat(900719925474099267n); +parseFloat('900719925474099267n');</code></pre> <h2 id="规范">规范</h2> diff --git a/files/zh-cn/web/javascript/reference/global_objects/parseint/index.html b/files/zh-cn/web/javascript/reference/global_objects/parseint/index.html index b3e5937b9b..8f28abb2ae 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/parseint/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/parseint/index.html @@ -33,7 +33,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/parseInt <dl> <dt><code><var>radix</var></code><var> {{optional_inline}}</var></dt> - <dd>从 <code>2</code> 到 <code>36</code>,表示字符串的基数。例如指定 <font face="consolas, Liberation Mono, courier, monospace"><span style="background-color: rgba(220, 220, 220, 0.5);">16</span></font> 表示被解析值是十六进制数。请注意,10不是默认值!</dd> + <dd>从 <code>2</code> 到 <code>36</code>,表示字符串的基数。例如指定 <font face="consolas, Liberation Mono, courier, monospace">16</font> 表示被解析值是十六进制数。请注意,10不是默认值!</dd> <dd class="blockIndicator warning">文章后面的<a href="#描述">描述</a>解释了当参数 <code>radix</code> 不传时该函数的具体行为。</dd> </dl> @@ -145,11 +145,11 @@ parseInt("08"); <h3 id="ECMAScript_5_移除了八进制解析" style="line-height: 24px;">ECMAScript 5 移除了八进制解析</h3> -<p>ECMAScript 5 规范不再允许<code>parseInt</code>函数的<span style="line-height: 19.0909080505371px;">实现环境把以<code>0</code>字符开始的字符串作为八进制数值</span>。ECMAScript 5 陈述如下:</p> +<p>ECMAScript 5 规范不再允许<code>parseInt</code>函数的实现环境把以<code>0</code>字符开始的字符串作为八进制数值。ECMAScript 5 陈述如下:</p> <p>根据给定radix,<code>parseInt</code>函数产生一个由字符串参数内容解析过来的整数值。字符串中开头的空白会被忽略。如果radix没有指定或者为0,参数会被假定以10为基数来解析,如果数值以字符对0x或0X开头,会假定以16为基数来解析。</p> -<p>这与<span style="line-height: 19.0909080505371px;">ECMAScript 3有所不同,ECMAScript 3仅仅是不提倡这种做法但并没有禁止这种做法。</span></p> +<p>这与ECMAScript 3有所不同,ECMAScript 3仅仅是不提倡这种做法但并没有禁止这种做法。</p> <p>直至2013年,很多实现环境并没有采取新的规范所规定的做法, 而且由于必须兼容旧版的浏览器,所以<strong>永远都要明确给出radix参数的值.</strong></p> diff --git a/files/zh-cn/web/javascript/reference/global_objects/promise/index.html b/files/zh-cn/web/javascript/reference/global_objects/promise/index.html index 653e2f0704..e8ff35c09e 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/promise/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/promise/index.html @@ -28,9 +28,9 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Promise <li><em>已拒绝(rejected)</em>: 意味着操作失败。</li> </ul> -<p>待定状态的 Promise 对象要么会通过一个值<em>被兑现(fulfilled)</em>,要么会通过一个原因(错误)<em>被拒绝(rejected)</em>。当这些情况之一发生时,我们用 promise 的 then 方法排列起来的相关处理程序就会被调用。如果 promise 在一个相应的处理程序被绑定时就已经被兑现或被拒绝了,那么这个处理程序就会被调用,因此<span style="line-height: 1.5;">在完成异步操作和绑定处理方法之间不会存在竞争状态。</span></p> +<p>待定状态的 Promise 对象要么会通过一个值<em>被兑现(fulfilled)</em>,要么会通过一个原因(错误)<em>被拒绝(rejected)</em>。当这些情况之一发生时,我们用 promise 的 then 方法排列起来的相关处理程序就会被调用。如果 promise 在一个相应的处理程序被绑定时就已经被兑现或被拒绝了,那么这个处理程序就会被调用,因此在完成异步操作和绑定处理方法之间不会存在竞争状态。</p> -<p>因为 <span style="font-family: consolas,monaco,andale mono,monospace;"><code>{{jsxref("Promise.then", "Promise.prototype.then")}}</code> </span>和 <code style="font-style: normal;">{{jsxref("Promise.catch", "Promise.prototype.catch")}}</code> 方法返回的是 promise, 所以它们可以被链式调用。</p> +<p>因为 <code>{{jsxref("Promise.then", "Promise.prototype.then")}}</code> 和 <code style="font-style: normal;">{{jsxref("Promise.catch", "Promise.prototype.catch")}}</code> 方法返回的是 promise, 所以它们可以被链式调用。</p> <p><img alt="" src="https://mdn.mozillademos.org/files/8633/promises.png" style="height: 297px; width: 801px;"></p> diff --git a/files/zh-cn/web/javascript/reference/global_objects/promise/promise/index.html b/files/zh-cn/web/javascript/reference/global_objects/promise/promise/index.html index e48243fcc9..e79512fa51 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/promise/promise/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/promise/promise/index.html @@ -19,7 +19,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Promise/Promise <dl> <dt><code>executor</code></dt> - <dd>这是一个双参函数,参数为<code>resolve<font face="Arial, x-locale-body, sans-serif"><span style="background-color: #ffffff;">和</span></font>reject</code>。<code>Promise</code>的实现会立即执行<code>executor</code>,并传入<code>resolve<font face="Arial, x-locale-body, sans-serif"><span style="background-color: #ffffff;">和</span></font>reject</code>函数(<code>Promise</code>构造器将会在返回新对象之前<code>executor</code>)。当<code>resolve</code>和<code>reject</code>函数被调用时,它们分别对promise执行<code>resolve</code>和<code>reject</code>。<code>executor</code>通常会触发一些异步运算,一旦运算成功完成,则<code>resolve</code>掉这个promise,如果出错则<code>reject</code>掉。如果<code>executor</code>函数执行时抛出异常,promise状态会变为<code>rejected</code>。<code>executor</code>的返回值也会被忽略。</dd> + <dd>这是一个双参函数,参数为<code>resolve<font face="Arial, x-locale-body, sans-serif">和</font>reject</code>。<code>Promise</code>的实现会立即执行<code>executor</code>,并传入<code>resolve<font face="Arial, x-locale-body, sans-serif">和</font>reject</code>函数(<code>Promise</code>构造器将会在返回新对象之前<code>executor</code>)。当<code>resolve</code>和<code>reject</code>函数被调用时,它们分别对promise执行<code>resolve</code>和<code>reject</code>。<code>executor</code>通常会触发一些异步运算,一旦运算成功完成,则<code>resolve</code>掉这个promise,如果出错则<code>reject</code>掉。如果<code>executor</code>函数执行时抛出异常,promise状态会变为<code>rejected</code>。<code>executor</code>的返回值也会被忽略。</dd> </dl> <h2 id="例子">例子</h2> diff --git a/files/zh-cn/web/javascript/reference/global_objects/promise/resolve/index.html b/files/zh-cn/web/javascript/reference/global_objects/promise/resolve/index.html index 6ca8158da1..ee41e7d824 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/promise/resolve/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/promise/resolve/index.html @@ -9,7 +9,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Promise/resolve --- <div>{{JSRef}}</div> -<div><code><strong>Promise.resolve(value)</strong></code>方法返回一个以给定值解析后的{{jsxref("Promise")}} 对象。如果这个值是一个 promise ,那么将返回这个 promise ;如果这个值是thenable(即带有{{jsxref("Promise.then", "\"then\" ")}}方法),返回的promise会“跟随”这个thenable的对象,采用它的最终状态;否则返回的promise将以此值完成。<span style="font-size: 1rem; letter-spacing: -0.00278rem;">此函数将类promise对象的多层嵌套展平。</span></div> +<div><code><strong>Promise.resolve(value)</strong></code>方法返回一个以给定值解析后的{{jsxref("Promise")}} 对象。如果这个值是一个 promise ,那么将返回这个 promise ;如果这个值是thenable(即带有{{jsxref("Promise.then", "\"then\" ")}}方法),返回的promise会“跟随”这个thenable的对象,采用它的最终状态;否则返回的promise将以此值完成。此函数将类promise对象的多层嵌套展平。</div> <div></div> diff --git a/files/zh-cn/web/javascript/reference/global_objects/proxy/proxy/setprototypeof/index.html b/files/zh-cn/web/javascript/reference/global_objects/proxy/proxy/setprototypeof/index.html index 48e7f6be60..d2b65b1a9c 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/proxy/proxy/setprototypeof/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/proxy/proxy/setprototypeof/index.html @@ -49,7 +49,7 @@ original_slug: Web/JavaScript/Reference/Global_Objects/Proxy/handler/setPrototyp <p>如果违反了下列规则,则proxy将抛出一个{{jsxref("TypeError")}}:</p> <ul> - <li><code><font face="Open Sans, arial, x-locale-body, sans-serif"><span style="background-color: #ffffff;">如果 </span></font>target</code> 不可扩展, 原型参数必须与<code>Object.getPrototypeOf(target)</code> 的值相同.</li> + <li><code><font face="Open Sans, arial, x-locale-body, sans-serif">如果 </font>target</code> 不可扩展, 原型参数必须与<code>Object.getPrototypeOf(target)</code> 的值相同.</li> </ul> <h2 id="示例">示例</h2> diff --git a/files/zh-cn/web/javascript/reference/global_objects/reflect/comparing_reflect_and_object_methods/index.html b/files/zh-cn/web/javascript/reference/global_objects/reflect/comparing_reflect_and_object_methods/index.html index e846cf7190..0bfa4fcb10 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/reflect/comparing_reflect_and_object_methods/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/reflect/comparing_reflect_and_object_methods/index.html @@ -129,7 +129,7 @@ original_slug: Web/JavaScript/Reference/Global_Objects/Reflect/比较_Reflect_ <td><code>ownKeys()</code></td> <td>N/A</td> <td> - <p>{{jsxref("Reflect.ownKeys()")}}返回一个属性名称<font face="consolas, Liberation Mono, courier, monospace"><span style="background-color: rgba(220, 220, 220, 0.5);">数组</span></font>,该属性名称映射到目标对象自己的属性键。如果目标不是<code>Object</code>,则抛出<code>TypeError</code>。</p> + <p>{{jsxref("Reflect.ownKeys()")}}返回一个属性名称<font face="consolas, Liberation Mono, courier, monospace">数组</font>,该属性名称映射到目标对象自己的属性键。如果目标不是<code>Object</code>,则抛出<code>TypeError</code>。</p> </td> </tr> </tbody> diff --git a/files/zh-cn/web/javascript/reference/global_objects/reflect/construct/index.html b/files/zh-cn/web/javascript/reference/global_objects/reflect/construct/index.html index 8c6c4e2126..174cab0ccb 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/reflect/construct/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/reflect/construct/index.html @@ -40,7 +40,7 @@ var obj = Reflect.construct(Foo, args); </pre> <h3 id="Reflect.construct_vs_Object.create"><code>Reflect.construct()</code> vs <code>Object.create()</code></h3> -<p><code><font face="Arial, x-locale-body, sans-serif"><span style="background-color: #ffffff;">在新语法</span></font>Reflect</code>出现之前,是通过明确指定构造函数和原型对象( 使用{{jsxref("Object.create()")}})来创建一个对象的。</p> +<p><code><font face="Arial, x-locale-body, sans-serif">在新语法</font>Reflect</code>出现之前,是通过明确指定构造函数和原型对象( 使用{{jsxref("Object.create()")}})来创建一个对象的。</p> <pre class="brush: js notranslate">function OneClass() { this.name = 'one'; @@ -68,7 +68,7 @@ console.log(obj2 instanceof OtherClass); // true</pre> <p>虽然两种方式结果相同,但在创建对象过程中仍一点不同。 </p> -<p><font face="Arial, x-locale-body, sans-serif"><span style="background-color: #ffffff;">当使用</span></font><code>Object.create()</code>和{{jsxref("Function.prototype.apply()")}}时,如果不使用<code>new</code>操作符调用构造函数,构造函数内部的<code>new.target</code>值会指向<code>undefined</code>。</p> +<p><font face="Arial, x-locale-body, sans-serif">当使用</font><code>Object.create()</code>和{{jsxref("Function.prototype.apply()")}}时,如果不使用<code>new</code>操作符调用构造函数,构造函数内部的<code>new.target</code>值会指向<code>undefined</code>。</p> <p>当调用<code>Reflect.construct()</code>来创建对象,<code>new.target</code>值会自动指定到<code>target</code>(或者newTarget,前提是newTarget指定了)。</p> @@ -97,7 +97,7 @@ OneClass.apply(obj3, args); // OneClass // undefined</pre> -<h2 id="举例"><font face="x-locale-heading-primary, zillaslab, Palatino, Palatino Linotype, x-locale-heading-secondary, serif"><span style="font-size: 37.33327865600586px;"><strong>举例</strong></span></font></h2> +<h2 id="举例"><font face="x-locale-heading-primary, zillaslab, Palatino, Palatino Linotype, x-locale-heading-secondary, serif"><strong>举例</strong></font></h2> <h3 id="使用_Reflect.construct">使用 <code>Reflect.construct()</code></h3> diff --git a/files/zh-cn/web/javascript/reference/global_objects/regexp/@@matchall/index.html b/files/zh-cn/web/javascript/reference/global_objects/regexp/@@matchall/index.html index d5aeafd16a..6f400c0ff2 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/regexp/@@matchall/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/regexp/@@matchall/index.html @@ -49,7 +49,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/RegExp/@@matchAll var str = '2016-01-02'; var result = re[Symbol.matchAll](str); -console.log(<span class="message-body-wrapper"><span class="message-flex-body"><span class="devtools-monospace message-body"><span class="cm-variable">Array</span>.<span class="cm-property">from</span>(<span class="cm-variable">result</span>, <span class="cm-def">x</span> <span class="cm-operator">=></span> <span class="cm-variable-2">x</span>[<span class="cm-number">0</span>])</span></span></span>); +console.log(Array.from(result, x => x[0])); // ["2016", "01", "02"] </pre> diff --git a/files/zh-cn/web/javascript/reference/global_objects/regexp/dotall/index.html b/files/zh-cn/web/javascript/reference/global_objects/regexp/dotall/index.html index 1dc070139f..37d3c9b92f 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/regexp/dotall/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/regexp/dotall/index.html @@ -20,8 +20,8 @@ translation_of: Web/JavaScript/Reference/Global_Objects/RegExp/dotAll <ul> <li>U+000A 换行符("<code>\n</code>")</li> <li>U+000D 回车符("<code>\r</code>")</li> - <li>U+2028 行分隔符(<span class="message-body-wrapper"><span class="message-flex-body"><span class="devtools-monospace message-body"><span class="objectBox objectBox-string">line separator</span></span></span></span>)</li> - <li>U+2029 段分隔符(<span class="message-body-wrapper"><span class="message-flex-body"><span class="devtools-monospace message-body"><span class="objectBox objectBox-string">paragraph separator</span></span></span></span>)</li> + <li>U+2028 行分隔符(line separator)</li> + <li>U+2029 段分隔符(paragraph separator)</li> </ul> <p>这实际上意味着"<code>.</code>"将会匹配任意的单个Unicode Basic Multilingual Plane (BMP)字符。若要使其与astral字符(大于\uFFFF的Unicode字符)匹配,你应当使用"<code>u</code>"(Unicode)修饰符。一起使用这两个修饰符,"<code>.</code>"将无一例外地匹配任意Unicode字符。</p> diff --git a/files/zh-cn/web/javascript/reference/global_objects/regexp/exec/index.html b/files/zh-cn/web/javascript/reference/global_objects/regexp/exec/index.html index 6648813f00..b7e9edf7ec 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/regexp/exec/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/regexp/exec/index.html @@ -14,7 +14,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/RegExp/exec <p><code><strong>exec() </strong></code>方法在一个指定字符串中执行一个搜索匹配。返回一个结果数组或 {{jsxref("null")}}。</p> -<p>在设置了 {{jsxref("RegExp.global", "global")}} 或 {{jsxref("RegExp.sticky", "sticky")}} 标志位的情况下(如 <code>/foo/g</code> or <code>/foo/y</code>),JavaScript {{jsxref("RegExp")}} 对象是<strong>有状态</strong>的。他们会将上次成功匹配后的位置记录在 <span style="font-size: 1rem; letter-spacing: -0.00278rem;">{{jsxref("RegExp.lastIndex", "lastIndex")}} 属性中。使用此特性,</span><code style="font-size: 1rem; letter-spacing: -0.00278rem;">exec()</code><span style="font-size: 1rem; letter-spacing: -0.00278rem;"> 可用来对单个字符串中的多次匹配结果进行逐条的遍历(包括捕获到的匹配),而相比之下, {{jsxref("String.prototype.match()")}} 只会返回匹配到的结果。</span></p> +<p>在设置了 {{jsxref("RegExp.global", "global")}} 或 {{jsxref("RegExp.sticky", "sticky")}} 标志位的情况下(如 <code>/foo/g</code> or <code>/foo/y</code>),JavaScript {{jsxref("RegExp")}} 对象是<strong>有状态</strong>的。他们会将上次成功匹配后的位置记录在 {{jsxref("RegExp.lastIndex", "lastIndex")}} 属性中。使用此特性,<code style="font-size: 1rem; letter-spacing: -0.00278rem;">exec()</code> 可用来对单个字符串中的多次匹配结果进行逐条的遍历(包括捕获到的匹配),而相比之下, {{jsxref("String.prototype.match()")}} 只会返回匹配到的结果。</p> <p>如果你只是为了判断是否匹配(true或 false),可以使用 {{jsxref("RegExp.test()")}} 方法,或者 {{jsxref("String.search()")}} 方法。</p> diff --git a/files/zh-cn/web/javascript/reference/global_objects/regexp/sticky/index.html b/files/zh-cn/web/javascript/reference/global_objects/regexp/sticky/index.html index f74b96499b..6060a9edc0 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/regexp/sticky/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/regexp/sticky/index.html @@ -75,7 +75,7 @@ regex2.test(".\nfoo"); // true - 索引2是行的开始 <div></div> -<h2 id="相关链接"><span style="">相关链接</span></h2> +<h2 id="相关链接">相关链接</h2> <ul> <li>{{jsxref("RegExp.lastIndex")}}</li> diff --git a/files/zh-cn/web/javascript/reference/global_objects/set/foreach/index.html b/files/zh-cn/web/javascript/reference/global_objects/set/foreach/index.html index e89be3af36..cd1bf7f82c 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/set/foreach/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/set/foreach/index.html @@ -18,9 +18,9 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Set/forEach <dd>为集合中每个元素执行的回调函数,该函数接收三个参数:</dd> <dd> <dl> - <dt><strong><font face="consolas, Liberation Mono, courier, monospace"><span style="background-color: rgba(220, 220, 220, 0.5);">currentValue</span>, </font></strong><strong><font face="consolas, Liberation Mono, courier, monospace"><span style="background-color: rgba(220, 220, 220, 0.5);">currentKey</span>{{optional_inline}}</font></strong></dt> + <dt><strong><font face="consolas, Liberation Mono, courier, monospace">currentValue, </font></strong><strong><font face="consolas, Liberation Mono, courier, monospace">currentKey{{optional_inline}}</font></strong></dt> <dd><strong>currentValue</strong> 是正在被操作的元素。并且由于集合没有索引,所以 <strong>currentKey</strong> 也表示这个正在被操作的元素。</dd> - <dt><strong><font face="consolas, Liberation Mono, courier, monospace"><span style="background-color: rgba(220, 220, 220, 0.5);">set</span>{{optional_inline}}</font></strong></dt> + <dt><strong><font face="consolas, Liberation Mono, courier, monospace">set{{optional_inline}}</font></strong></dt> <dd>调用当前 <code>forEach</code> 方法的集合对象</dd> </dl> </dd> @@ -54,7 +54,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Set/forEach <h3 id="输出集合对象的内容">输出集合对象的内容</h3> -<p><span class="outputBox-2liU7_0">以下代码依次打印集合对象的元素:</span></p> +<p>以下代码依次打印集合对象的元素:</p> <pre class="brush:js">function logSetElements(value1, value2, set) { console.log("s[" + value1 + "] = " + value2); diff --git a/files/zh-cn/web/javascript/reference/global_objects/set/has/index.html b/files/zh-cn/web/javascript/reference/global_objects/set/has/index.html index e9edc5d978..1ffca26498 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/set/has/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/set/has/index.html @@ -35,19 +35,19 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Set/has <h3 id="Example:_Testing_size_of_all_array_elements" name="Example:_Testing_size_of_all_array_elements">使用 <code>has</code> 方法</h3> -<pre class="brush: js line-numbers language-js"><code class="language-js"><span class="keyword token">var</span> mySet <span class="operator token">=</span> <span class="keyword token">new</span> <span class="class-name token">Set</span><span class="punctuation token">(</span><span class="punctuation token">)</span><span class="punctuation token">;</span> -mySet<span class="punctuation token">.</span><span class="function token">add</span><span class="punctuation token">(</span><span class="string token">'foo'</span><span class="punctuation token">)</span><span class="punctuation token">;</span> +<pre class="brush: js line-numbers language-js"><code class="language-js">var mySet = new Set(); +mySet.add('foo'); -mySet<span class="punctuation token">.</span><span class="function token">has</span><span class="punctuation token">(</span><span class="string token">'foo'</span><span class="punctuation token">)</span><span class="punctuation token">;</span> <span class="comment token">// 返回 true</span> -mySet<span class="punctuation token">.</span><span class="function token">has</span><span class="punctuation token">(</span><span class="string token">'bar'</span><span class="punctuation token">)</span><span class="punctuation token">;</span> <span class="comment token">// 返回 false</span> +mySet.has('foo'); // 返回 true +mySet.has('bar'); // 返回 false -<span class="keyword token">var</span> set1 <span class="operator token">=</span> <span class="keyword token">new</span> <span class="class-name token">Set</span><span class="punctuation token">(</span><span class="punctuation token">)</span><span class="punctuation token">;</span> -<span class="keyword token">var</span> obj1 <span class="operator token">=</span> <span class="punctuation token">{</span><span class="string token">'key1'</span><span class="punctuation token">:</span> <span class="number token">1</span><span class="punctuation token">}</span><span class="punctuation token">;</span> -set1<span class="punctuation token">.</span><span class="function token">add</span><span class="punctuation token">(</span>obj1<span class="punctuation token">)</span><span class="punctuation token">;</span> +var set1 = new Set(); +var obj1 = {'key1': 1}; +set1.add(obj1); -set1<span class="punctuation token">.</span><span class="function token">has</span><span class="punctuation token">(</span>obj1<span class="punctuation token">)</span><span class="punctuation token">;</span> <span class="comment token">// 返回 true</span> -set1<span class="punctuation token">.</span><span class="function token">has</span><span class="punctuation token">(</span><span class="punctuation token">{</span><span class="string token">'key1'</span><span class="punctuation token">:</span> <span class="number token">1</span><span class="punctuation token">}</span><span class="punctuation token">)</span><span class="punctuation token">;</span> <span class="comment token">// 会返回 false,因为其是另一个对象的引用</span> -set1<span class="punctuation token">.</span><span class="function token">add</span><span class="punctuation token">(</span><span class="punctuation token">{</span><span class="string token">'key1'</span><span class="punctuation token">:</span> <span class="number token">1</span><span class="punctuation token">}</span><span class="punctuation token">)</span><span class="punctuation token">;</span> <span class="comment token">// 现在 set1 中有2条(不同引用的)对象了</span></code></pre> +set1.has(obj1); // 返回 true +set1.has({'key1': 1}); // 会返回 false,因为其是另一个对象的引用 +set1.add({'key1': 1}); // 现在 set1 中有2条(不同引用的)对象了</code></pre> <h2 id="规范">规范</h2> @@ -118,7 +118,7 @@ set1<span class="punctuation token">.</span><span class="function token">add</sp </table> </div> -<h2 id="相关连接"><span style="font-size: 30px; letter-spacing: -1px; line-height: 30px;"><strong>相关连接</strong></span></h2> +<h2 id="相关连接"><strong>相关连接</strong></h2> <ul> <li>{{jsxref("Set")}}</li> diff --git a/files/zh-cn/web/javascript/reference/global_objects/set/set/index.html b/files/zh-cn/web/javascript/reference/global_objects/set/set/index.html index 2ead74e30a..a3ae2c0278 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/set/set/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/set/set/index.html @@ -10,7 +10,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Set/Set --- <div>{{JSRef}}</div> -<p><span class="seoSummary"><strong><code>Set</code> 构造函数</strong>能让你创建 <code>Set</code> 对象,其可以存储任意类型的唯一值,无论是 <a href="/en-US/docs/Glossary/Primitive">primitive values</a> 或者对象引用。</span></p> +<p><strong><code>Set</code> 构造函数</strong>能让你创建 <code>Set</code> 对象,其可以存储任意类型的唯一值,无论是 <a href="/en-US/docs/Glossary/Primitive">primitive values</a> 或者对象引用。</p> <div>{{EmbedInteractiveExample("pages/js/set-prototype-constructor.html")}}</div> diff --git a/files/zh-cn/web/javascript/reference/global_objects/string/fixed/index.html b/files/zh-cn/web/javascript/reference/global_objects/string/fixed/index.html index f4af9c1103..03576dd5a1 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/string/fixed/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/string/fixed/index.html @@ -22,7 +22,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/String/fixed <h2 id="描述">描述</h2> -<p id="fixed()_方法将一个字符串包裹在<tt><tt>标签中,比如_<tt>str<tt>."><code style="font-size: 14px; font-style: normal; font-weight: normal; line-height: 1.5;">fixed()</code><span style="font-size: 14px; font-weight: normal; line-height: 1.5;"> 方法将一个字符串包裹在<tt></tt>标签中,比如</span><span style="font-size: 14px; font-weight: normal; line-height: 1.5;">: </span><code style="font-size: 14px; font-style: normal; font-weight: normal; line-height: 1.5;">"<tt>str</tt>"</code><span style="font-size: 14px; font-weight: normal; line-height: 1.5;">.</span></p> +<p id="fixed()_方法将一个字符串包裹在<tt><tt>标签中,比如_<tt>str<tt>."><code style="font-size: 14px; font-style: normal; font-weight: normal; line-height: 1.5;">fixed()</code> 方法将一个字符串包裹在<tt></tt>标签中,比如: <code style="font-size: 14px; font-style: normal; font-weight: normal; line-height: 1.5;">"<tt>str</tt>"</code>.</p> <h2 id="举例">举例</h2> diff --git a/files/zh-cn/web/javascript/reference/global_objects/string/index.html b/files/zh-cn/web/javascript/reference/global_objects/string/index.html index d8b23c0904..5cea932350 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/string/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/string/index.html @@ -245,7 +245,7 @@ console.log(String.replace(num, /5/, '2')); <p class="brush: js">移除字符串泛型的措施,参见 <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Deprecated_string_generics">Warning: String.x is deprecated; use String.prototype.x instead</a>.</p> -<p class="brush: js"><span style="background-color: #ffffff; color: #4d4e53; font-family: open sans,arial,sans-serif; font-size: 14px; line-height: 21px;">{{jsxref("Global_Objects/Array", "Generics", "#Array_generic_methods", 1)}} 在 Javascript 1.6 中同样支持{{jsxref("Global_Objects/Array", "Array")}}。</span></p> +<p class="brush: js">{{jsxref("Global_Objects/Array", "Generics", "#Array_generic_methods", 1)}} 在 Javascript 1.6 中同样支持{{jsxref("Global_Objects/Array", "Array")}}。</p> <h2 id="String_instances" name="String_instances"><code>String</code> 实例</h2> @@ -253,7 +253,7 @@ console.log(String.replace(num, /5/, '2')); <p>{{page('zh-CN/docs/Web/JavaScript/Reference/Global_Objects/String/prototype', 'Properties')}}</p> -<p><span style="line-height: 1.5;">{{page('zh-CN/docs/Web/JavaScript/Reference/Global_Objects/String/prototype', 'Methods')}}</span></p> +<p>{{page('zh-CN/docs/Web/JavaScript/Reference/Global_Objects/String/prototype', 'Methods')}}</p> <h2 id="示例">示例 </h2> diff --git a/files/zh-cn/web/javascript/reference/global_objects/string/lastindexof/index.html b/files/zh-cn/web/javascript/reference/global_objects/string/lastindexof/index.html index 3c3e51d666..e4b6dd8681 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/string/lastindexof/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/string/lastindexof/index.html @@ -3,7 +3,7 @@ title: String.prototype.lastIndexOf() slug: Web/JavaScript/Reference/Global_Objects/String/lastIndexOf translation_of: Web/JavaScript/Reference/Global_Objects/String/lastIndexOf --- -<p><span class="hidden"> </span>{{JSRef}}</p> +<p> {{JSRef}}</p> <p> <strong><code>lastIndexOf()</code></strong> 方法返回调用{{jsxref("String")}} 对象的指定值最后一次出现的索引,在一个字符串中的指定位置 <code>fromIndex</code>处从后向前搜索。如果没找到这个特定值则返回-1 。</p> diff --git a/files/zh-cn/web/javascript/reference/global_objects/string/localecompare/index.html b/files/zh-cn/web/javascript/reference/global_objects/string/localecompare/index.html index 9a55c1bb88..e7948450a1 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/string/localecompare/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/string/localecompare/index.html @@ -28,7 +28,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/String/localeCompare <dl> <dt><code>compareString</code></dt> <dd>用来比较的字符串</dd> - <dt><strong><code><font face="consolas, Liberation Mono, courier, monospace"><span style="background-color: #eeeeee;">locales</span></font></code></strong></dt> + <dt><strong><code><font face="consolas, Liberation Mono, courier, monospace">locales</font></code></strong></dt> <dd>可选。 用来表示一种或多种语言或区域的一个符合 <a href="https://tools.ietf.org/html/rfc5646">BCP 47</a> 标准的字符串或一个字符串数组。 <code>locales</code>参数的一般形式与解释, 详情请参考 <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#Locale_identification_and_negotiation">Intl page</a>。 下列的 Unicode 扩展关键词是允许的:</dd> <dd><code><strong>co</strong></code></dd> <dd>为了某些地域多样的排序规则。可能的值包括: <code>"big5han"</code>, <code>"dict"</code>, <code>"direct"</code>, <code>"ducet"</code>, <code>"gb2312"</code>, <code>"phonebk"</code>, <code>"phonetic"</code>, <code>"pinyin"</code>, <code>"reformed"</code>, <code>"searchjl"</code>, <code>"stroke"</code>, <code>"trad"</code>, <code>"unihan"</code>。 <code>"standard"</code> 和<code>"search"</code> 这两个值是被忽略的; 它们被 <code>options</code> 的属性 <code>usage</code> 代替(往下看)。</dd> diff --git a/files/zh-cn/web/javascript/reference/global_objects/string/match/index.html b/files/zh-cn/web/javascript/reference/global_objects/string/match/index.html index 9922ea3291..cc979f7ffe 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/string/match/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/string/match/index.html @@ -26,8 +26,8 @@ translation_of: Web/JavaScript/Reference/Global_Objects/String/match <h3 id="返回值">返回值</h3> <ul> - <li><span style="line-height: 1.572;">如果使用g标志,则将返回与完整正则表达式匹配的所有结果,但不会返回捕获组。</span></li> - <li>如果未使用g标志,则仅返回第一个完整匹配及其相关的捕获组<span style="line-height: 1.572;">(<code>Array</code>)</span>。 在这种情况下,返回的项目将具有如下所述的其他属性。</li> + <li>如果使用g标志,则将返回与完整正则表达式匹配的所有结果,但不会返回捕获组。</li> + <li>如果未使用g标志,则仅返回第一个完整匹配及其相关的捕获组(<code>Array</code>)。 在这种情况下,返回的项目将具有如下所述的其他属性。</li> </ul> <h4 id="附加属性">附加属性</h4> @@ -62,56 +62,56 @@ translation_of: Web/JavaScript/Reference/Global_Objects/String/match <p>在下例中,使用 <code>match</code> 查找 "<code>Chapter</code>" 紧跟着 1 个或多个数值字符,再紧跟着一个小数点和数值字符 0 次或多次。正则表达式包含 <code>i</code> 标志,因此大小写会被忽略。</p> -<pre class="brush: js line-numbers language-js notranslate"><code class="language-js"><span class="keyword token">var</span> str <span class="operator token">=</span> <span class="string token">'For more information, see Chapter 3.4.5.1'</span><span class="punctuation token">;</span> -<span class="keyword token">var</span> re <span class="operator token">=</span> <span class="regex token">/see (chapter \d+(\.\d)*)/i</span><span class="punctuation token">;</span> -<span class="keyword token">var</span> found <span class="operator token">=</span> str<span class="punctuation token">.</span><span class="function token">match</span><span class="punctuation token">(</span>re<span class="punctuation token">)</span><span class="punctuation token">;</span> +<pre class="brush: js line-numbers language-js notranslate"><code class="language-js">var str = 'For more information, see Chapter 3.4.5.1'; +var re = /see (chapter \d+(\.\d)*)/i; +var found = str.match(re); -console<span class="punctuation token">.</span><span class="function token">log</span><span class="punctuation token">(</span>found<span class="punctuation token">)</span><span class="punctuation token">;</span> +console.log(found); -<span class="comment token">// logs [ 'see Chapter 3.4.5.1',</span> -<span class="comment token">// 'Chapter 3.4.5.1',</span> -<span class="comment token">// '.1',</span> -<span class="comment token">// index: 22,</span> -<span class="comment token">// input: 'For more information, see Chapter 3.4.5.1' ]</span> +// logs [ 'see Chapter 3.4.5.1', +// 'Chapter 3.4.5.1', +// '.1', +// index: 22, +// input: 'For more information, see Chapter 3.4.5.1' ] -<span class="comment token">// 'see Chapter 3.4.5.1' 是整个匹配。</span> -<span class="comment token">// 'Chapter 3.4.5.1' 被'(chapter \d+(\.\d)*)'捕获。</span> -<span class="comment token">// '.1' 是被'(\.\d)'捕获的最后一个值。</span> -<span class="comment token">// 'index' 属性(22) 是整个匹配从零开始的索引。</span> -<span class="comment token">// 'input' 属性是被解析的原始字符串。</span></code></pre> +// 'see Chapter 3.4.5.1' 是整个匹配。 +// 'Chapter 3.4.5.1' 被'(chapter \d+(\.\d)*)'捕获。 +// '.1' 是被'(\.\d)'捕获的最后一个值。 +// 'index' 属性(22) 是整个匹配从零开始的索引。 +// 'input' 属性是被解析的原始字符串。</code></pre> <h3 id="Example_Using_global_and_ignore_case_flags_with_match" name="Example:_Using_global_and_ignore_case_flags_with_match">例子:<code>match</code> 使用全局(global)和忽略大小写(ignore case)标志</h3> <p>下例展示了 <code>match</code> 使用 global 和 ignore case 标志。A-E、a-e 的所有字母将会作为一个数组的元素返回。</p> -<pre class="brush: js line-numbers language-js notranslate"><code class="language-js"><span class="keyword token">var</span> str <span class="operator token">=</span> <span class="string token">'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'</span><span class="punctuation token">;</span> -<span class="keyword token">var</span> regexp <span class="operator token">=</span> <span class="regex token">/[A-E]/gi</span><span class="punctuation token">;</span> -<span class="keyword token">var</span> matches_array <span class="operator token">=</span> str<span class="punctuation token">.</span><span class="function token">match</span><span class="punctuation token">(</span>regexp<span class="punctuation token">)</span><span class="punctuation token">;</span> +<pre class="brush: js line-numbers language-js notranslate"><code class="language-js">var str = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; +var regexp = /[A-E]/gi; +var matches_array = str.match(regexp); -console<span class="punctuation token">.</span><span class="function token">log</span><span class="punctuation token">(</span>matches_array<span class="punctuation token">)</span><span class="punctuation token">;</span> -<span class="comment token">// ['A', 'B', 'C', 'D', 'E', 'a', 'b', 'c', 'd', 'e']</span></code></pre> +console.log(matches_array); +// ['A', 'B', 'C', 'D', 'E', 'a', 'b', 'c', 'd', 'e']</code></pre> <h3 id="使用match,不传参数"><code>使用match(),不传参数 </code></h3> -<pre class="brush: js line-numbers language-js notranslate"><code class="language-js"><span class="keyword token">var</span> str <span class="operator token">=</span> <span class="string token">"Nothing will come of nothing."</span><span class="punctuation token">;</span> +<pre class="brush: js line-numbers language-js notranslate"><code class="language-js">var str = "Nothing will come of nothing."; -str<span class="punctuation token">.</span><span class="function token">match</span><span class="punctuation token">(</span><span class="punctuation token">)</span><span class="punctuation token">;</span> <span class="comment token">// returns [""]</span></code></pre> +str.match(); // returns [""]</code></pre> <h3 id="一个非正则表达式对象作为参数">一个非正则表达式对象作为参数</h3> <p>当参数是一个字符串或一个数字,它会使用new RegExp(obj)来隐式转换成一个 {{jsxref("RegExp")}}。如果它是一个有正号的正数,RegExp() 方法将忽略正号。</p> -<pre class="brush: js line-numbers language-js notranslate"><code class="language-js"><span class="keyword token">var</span> str1 <span class="operator token">=</span> <span class="string token">"NaN means not a number. Infinity contains -Infinity and +Infinity in JavaScript."</span><span class="punctuation token">,</span> - str2 <span class="operator token">=</span> <span class="string token">"My grandfather is 65 years old and My grandmother is 63 years old."</span><span class="punctuation token">,</span> - str3 <span class="operator token">=</span> <span class="string token">"The contract was declared null and void."</span><span class="punctuation token">;</span> -str1<span class="punctuation token">.</span><span class="function token">match</span><span class="punctuation token">(</span><span class="string token">"number"</span><span class="punctuation token">)</span><span class="punctuation token">;</span> <span class="comment token">// "number" 是字符串。返回["number"]</span> -str1<span class="punctuation token">.</span><span class="function token">match</span><span class="punctuation token">(</span><span class="number token">NaN</span><span class="punctuation token">)</span><span class="punctuation token">;</span> <span class="comment token">// NaN的类型是number。返回["NaN"]</span> -str1<span class="punctuation token">.</span><span class="function token">match</span><span class="punctuation token">(</span><span class="number token">Infinity</span><span class="punctuation token">)</span><span class="punctuation token">;</span> <span class="comment token">// Infinity的类型是number。返回["Infinity"]</span> -str1<span class="punctuation token">.</span><span class="function token">match</span><span class="punctuation token">(</span><span class="operator token">+</span><span class="number token">Infinity</span><span class="punctuation token">)</span><span class="punctuation token">;</span> <span class="comment token">// 返回["Infinity"]</span> -str1<span class="punctuation token">.</span><span class="function token">match</span><span class="punctuation token">(</span><span class="operator token">-</span><span class="number token">Infinity</span><span class="punctuation token">)</span><span class="punctuation token">;</span> <span class="comment token">// 返回["-Infinity"]</span> -str2<span class="punctuation token">.</span><span class="function token">match</span><span class="punctuation token">(</span><span class="number token">65</span><span class="punctuation token">)</span><span class="punctuation token">;</span> <span class="comment token">// 返回["65"]</span> -str2<span class="punctuation token">.</span><span class="function token">match</span><span class="punctuation token">(</span><span class="operator token">+</span><span class="number token">65</span><span class="punctuation token">)</span><span class="punctuation token">;</span> <span class="comment token">// 有正号的number。返回["65"]</span> -str3<span class="punctuation token">.</span><span class="function token">match</span><span class="punctuation token">(</span><span class="keyword token">null</span><span class="punctuation token">)</span><span class="punctuation token">;</span> <span class="comment token">// 返回["null"]</span></code></pre> +<pre class="brush: js line-numbers language-js notranslate"><code class="language-js">var str1 = "NaN means not a number. Infinity contains -Infinity and +Infinity in JavaScript.", + str2 = "My grandfather is 65 years old and My grandmother is 63 years old.", + str3 = "The contract was declared null and void."; +str1.match("number"); // "number" 是字符串。返回["number"] +str1.match(NaN); // NaN的类型是number。返回["NaN"] +str1.match(Infinity); // Infinity的类型是number。返回["Infinity"] +str1.match(+Infinity); // 返回["Infinity"] +str1.match(-Infinity); // 返回["-Infinity"] +str2.match(65); // 返回["65"] +str2.match(+65); // 有正号的number。返回["65"] +str3.match(null); // 返回["null"]</code></pre> <h2 id="规范">规范</h2> diff --git a/files/zh-cn/web/javascript/reference/global_objects/string/normalize/index.html b/files/zh-cn/web/javascript/reference/global_objects/string/normalize/index.html index d88c6826a0..f14e1d4a36 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/string/normalize/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/string/normalize/index.html @@ -54,7 +54,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/String/normalize <dl> <dt>{{jsxref("RangeError")}}</dt> - <dd>如果给 <code>form</code> 传入了上述四个字符串以外的参数,则会抛出 <span><code>RangeError</code> 异常。</span></dd> + <dd>如果给 <code>form</code> 传入了上述四个字符串以外的参数,则会抛出 <code>RangeError</code> 异常。</dd> </dl> <h2 id="描述">描述</h2> diff --git a/files/zh-cn/web/javascript/reference/global_objects/string/repeat/index.html b/files/zh-cn/web/javascript/reference/global_objects/string/repeat/index.html index ce35065f1a..b880c16b92 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/string/repeat/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/string/repeat/index.html @@ -44,59 +44,59 @@ translation_of: Web/JavaScript/Reference/Global_Objects/String/repeat <p>此方法已添加到 ECMAScript 2015 规范中,并且可能尚未在所有 JavaScript 实现中可用。然而,你可以使用以下代码段对 String.prototype.repeat() 进行填充:</p> -<pre class="brush: js language-js notranslate"><code class="language-js"><span class="keyword token">if</span> <span class="punctuation token">(</span><span class="operator token">!</span>String<span class="punctuation token">.</span>prototype<span class="punctuation token">.</span>repeat<span class="punctuation token">)</span> <span class="punctuation token">{</span> - String<span class="punctuation token">.</span>prototype<span class="punctuation token">.</span>repeat <span class="operator token">=</span> <span class="keyword token">function</span><span class="punctuation token">(</span>count<span class="punctuation token">)</span> <span class="punctuation token">{</span> - <span class="string token">'use strict'</span><span class="punctuation token">;</span> - <span class="keyword token">if</span> <span class="punctuation token">(</span><span class="keyword token">this</span> <span class="operator token">==</span> <span class="keyword token">null</span><span class="punctuation token">)</span> <span class="punctuation token">{</span> - <span class="keyword token">throw</span> <span class="keyword token">new</span> <span class="class-name token">TypeError</span><span class="punctuation token">(</span><span class="string token">'can\'t convert '</span> <span class="operator token">+</span> <span class="keyword token">this</span> <span class="operator token">+</span> <span class="string token">' to object'</span><span class="punctuation token">)</span><span class="punctuation token">;</span> - <span class="punctuation token">}</span> - <span class="keyword token">var</span> str <span class="operator token">=</span> <span class="string token">''</span> <span class="operator token">+</span> <span class="keyword token">this</span><span class="punctuation token">;</span> - count <span class="operator token">=</span> <span class="operator token">+</span>count<span class="punctuation token">;</span> - <span class="keyword token">if</span> <span class="punctuation token">(</span>count <span class="operator token">!</span><span class="operator token">=</span> count<span class="punctuation token">)</span> <span class="punctuation token">{</span> - count <span class="operator token">=</span> <span class="number token">0</span><span class="punctuation token">;</span> - <span class="punctuation token">}</span> - <span class="keyword token">if</span> <span class="punctuation token">(</span>count <span class="operator token"><</span> <span class="number token">0</span><span class="punctuation token">)</span> <span class="punctuation token">{</span> - <span class="keyword token">throw</span> <span class="keyword token">new</span> <span class="class-name token">RangeError</span><span class="punctuation token">(</span><span class="string token">'repeat count must be non-negative'</span><span class="punctuation token">)</span><span class="punctuation token">;</span> - <span class="punctuation token">}</span> - <span class="keyword token">if</span> <span class="punctuation token">(</span>count <span class="operator token">==</span> <span class="number token">Infinity</span><span class="punctuation token">)</span> <span class="punctuation token">{</span> - <span class="keyword token">throw</span> <span class="keyword token">new</span> <span class="class-name token">RangeError</span><span class="punctuation token">(</span><span class="string token">'repeat count must be less than infinity'</span><span class="punctuation token">)</span><span class="punctuation token">;</span> - <span class="punctuation token">}</span> - count <span class="operator token">=</span> Math<span class="punctuation token">.</span><span class="function token">floor<span class="punctuation token">(</span></span>count<span class="punctuation token">)</span><span class="punctuation token">;</span> - <span class="keyword token">if</span> <span class="punctuation token">(</span>str<span class="punctuation token">.</span>length <span class="operator token">==</span> <span class="number token">0</span> <span class="operator token">||</span> count <span class="operator token">==</span> <span class="number token">0</span><span class="punctuation token">)</span> <span class="punctuation token">{</span> - <span class="keyword token">return</span> <span class="string token">''</span><span class="punctuation token">;</span> - <span class="punctuation token">}</span> - <span class="comment token"> // 确保 count 是一个 31 位的整数。这样我们就可以使用如下优化的算法。 - // 当前(2014年8月),绝大多数浏览器都不能支持 1 << 28 长的字符串,所以:</span><span class="comment token"> -</span> <span class="keyword token">if</span> <span class="punctuation token">(</span>str<span class="punctuation token">.</span>length <span class="operator token">*</span> count <span class="operator token">>=</span> <span class="number token">1</span> <span class="operator token"><</span><span class="operator token"><</span> <span class="number token">28</span><span class="punctuation token">)</span> <span class="punctuation token">{</span> - <span class="keyword token">throw</span> <span class="keyword token">new</span> <span class="class-name token">RangeError</span><span class="punctuation token">(</span><span class="string token">'repeat count must not overflow maximum string size'</span><span class="punctuation token">)</span><span class="punctuation token">;</span> - <span class="punctuation token">}</span> - <span class="keyword token">var</span> rpt <span class="operator token">=</span> <span class="string token">''</span><span class="punctuation token">;</span> - <span class="keyword token">for</span> <span class="punctuation token">(</span><span class="punctuation token">;</span><span class="punctuation token">;</span><span class="punctuation token">)</span> <span class="punctuation token">{</span> - <span class="keyword token">if</span> <span class="punctuation token">(</span><span class="punctuation token">(</span>count <span class="operator token">&</span> <span class="number token">1</span><span class="punctuation token">)</span> <span class="operator token">==</span> <span class="number token">1</span><span class="punctuation token">)</span> <span class="punctuation token">{</span> - rpt <span class="operator token">+</span><span class="operator token">=</span> str<span class="punctuation token">;</span> - <span class="punctuation token">}</span> - count <span class="operator token">></span><span class="operator token">></span><span class="operator token">>=</span> <span class="number token">1</span><span class="punctuation token">;</span> - <span class="keyword token">if</span> <span class="punctuation token">(</span>count <span class="operator token">==</span> <span class="number token">0</span><span class="punctuation token">)</span> <span class="punctuation token">{</span> - <span class="keyword token">break</span><span class="punctuation token">;</span> - <span class="punctuation token">}</span> - str <span class="operator token">+</span><span class="operator token">=</span> str<span class="punctuation token">;</span> - <span class="punctuation token">}</span> - <span class="keyword token">return</span> rpt<span class="punctuation token">;</span> - <span class="punctuation token">}</span> -<span class="punctuation token">}</span></code></pre> +<pre class="brush: js language-js notranslate"><code class="language-js">if (!String.prototype.repeat) { + String.prototype.repeat = function(count) { + 'use strict'; + if (this == null) { + throw new TypeError('can\'t convert ' + this + ' to object'); + } + var str = '' + this; + count = +count; + if (count != count) { + count = 0; + } + if (count < 0) { + throw new RangeError('repeat count must be non-negative'); + } + if (count == Infinity) { + throw new RangeError('repeat count must be less than infinity'); + } + count = Math.floor(count); + if (str.length == 0 || count == 0) { + return ''; + } + // 确保 count 是一个 31 位的整数。这样我们就可以使用如下优化的算法。 + // 当前(2014年8月),绝大多数浏览器都不能支持 1 << 28 长的字符串,所以: + if (str.length * count >= 1 << 28) { + throw new RangeError('repeat count must not overflow maximum string size'); + } + var rpt = ''; + for (;;) { + if ((count & 1) == 1) { + rpt += str; + } + count >>>= 1; + if (count == 0) { + break; + } + str += str; + } + return rpt; + } +}</code></pre> <h2 id="Examples" name="Examples">示例</h2> -<pre class="brush:js notranslate"><span class="difflineplus">"abc".repeat(-1) // </span>RangeError: repeat count must be positive and less than inifinity -<span class="difflineplus">"abc".repeat(0) // ""</span> -<span class="difflineplus">"abc".repeat(1) // "abc"</span> -<span class="difflineplus">"abc".repeat(2) // "</span>abcabc<span class="difflineplus">" -</span>"abc".repeat(3.5)<span class="difflineplus"> // "abcabcabc" 参数count将会被自动转换成整数. -</span><span class="difflineplus">"abc".repeat(1/0) //</span> RangeError: repeat count must be positive and less than inifinity +<pre class="brush:js notranslate">"abc".repeat(-1) // RangeError: repeat count must be positive and less than inifinity +"abc".repeat(0) // "" +"abc".repeat(1) // "abc" +"abc".repeat(2) // "abcabc" +"abc".repeat(3.5) // "abcabcabc" 参数count将会被自动转换成整数. +"abc".repeat(1/0) // RangeError: repeat count must be positive and less than inifinity -<span class="difflineplus">({toString : () => "abc", repeat : String.prototype.repeat}</span><span class="difflineplus">).repeat(2) -</span><span class="difflineplus">//"</span>abcabc<span class="difflineplus">",repeat是一个通用方法</span>,也就是它的调用者可以不是一个字符串对象.</pre> +({toString : () => "abc", repeat : String.prototype.repeat}).repeat(2) +//"abcabc",repeat是一个通用方法,也就是它的调用者可以不是一个字符串对象.</pre> <h2 id="规范">规范</h2> diff --git a/files/zh-cn/web/javascript/reference/global_objects/string/replace/index.html b/files/zh-cn/web/javascript/reference/global_objects/string/replace/index.html index 45421c8b54..49f27efe4b 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/string/replace/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/string/replace/index.html @@ -193,7 +193,7 @@ console.log(newstr); } </pre> -<p>运行 <code>styleHyphenFormat('borderTop')</code><code>,</code><span>将</span><span>返回 'border-top'。</span></p> +<p>运行 <code>styleHyphenFormat('borderTop')</code><code>,</code>将返回 'border-top'。</p> <p>因为我们想在最终的替换中进一步转变匹配结果,所以我们必须使用一个函数。这迫使我们在使用{{jsxref("String.prototype.toLowerCase()", "toLowerCase()")}}方法前进行评估。如果我们尝试不用一个函数进行匹配,那么使用{{jsxref("String.prototype.toLowerCase()", "toLowerCase()")}} 方法将不会有效。</p> diff --git a/files/zh-cn/web/javascript/reference/global_objects/string/replaceall/index.html b/files/zh-cn/web/javascript/reference/global_objects/string/replaceall/index.html index 69c92e87dc..cbd76d71b7 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/string/replaceall/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/string/replaceall/index.html @@ -9,7 +9,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/String/replaceAll --- <div>{{JSRef}}</div> -<p><span class="seoSummary"><strong><code>replaceAll()</code></strong> 方法返回一个新字符串,新字符串所有满足 <code>pattern</code> 的部分都已被<code>replacement</code> 替换。</span><span class="seoSummary"><code>pattern</code></span>可以是一个字符串或一个 {{jsxref("RegExp")}}, <code>replacement</code>可以是一个字符串或一个在每次匹配被调用的函数。</p> +<p><strong><code>replaceAll()</code></strong> 方法返回一个新字符串,新字符串所有满足 <code>pattern</code> 的部分都已被<code>replacement</code> 替换。<code>pattern</code>可以是一个字符串或一个 {{jsxref("RegExp")}}, <code>replacement</code>可以是一个字符串或一个在每次匹配被调用的函数。</p> <p>原始字符串保持不变。</p> diff --git a/files/zh-cn/web/javascript/reference/global_objects/string/slice/index.html b/files/zh-cn/web/javascript/reference/global_objects/string/slice/index.html index df8f398983..35f5dd5736 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/string/slice/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/string/slice/index.html @@ -29,7 +29,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/String/slice <dt><code>beginIndex</code></dt> <dd>从该索引(以 0 为基数)处开始提取原字符串中的字符。如果值为负数,会被当做 <code>strLength + beginIndex</code> 看待,这里的<code>strLength</code> 是字符串的长度(例如, 如果 <code>beginIndex</code> 是 -3 则看作是:<code>strLength - 3</code>)</dd> <dt><code>endIndex</code></dt> - <dd>可选。在该索引(以 0 为基数)处结束提取字符串。如果省略该参数,<code style="font-style: normal;">slice()</code> 会一直提取到字符串末尾。<span style="line-height: 1.5;">如果该参数为负数,则被看作是 strLength + endIndex,这里的 strLength 就是字符串的长度(例如,如果 endIndex 是 -3,则是, strLength - 3)。</span></dd> + <dd>可选。在该索引(以 0 为基数)处结束提取字符串。如果省略该参数,<code style="font-style: normal;">slice()</code> 会一直提取到字符串末尾。如果该参数为负数,则被看作是 strLength + endIndex,这里的 strLength 就是字符串的长度(例如,如果 endIndex 是 -3,则是, strLength - 3)。</dd> </dl> <h3 id="返回值">返回值</h3> diff --git a/files/zh-cn/web/javascript/reference/global_objects/string/startswith/index.html b/files/zh-cn/web/javascript/reference/global_objects/string/startswith/index.html index 747878e5b9..7cbd48ba7b 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/string/startswith/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/string/startswith/index.html @@ -13,7 +13,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/String/startsWith --- <div>{{JSRef}}</div> -<p><span class="seoSummary"><code><strong>startsWith()</strong></code> 方法用来判断当前字符串是否以另外一个给定的子字符串开头,并根据判断结果返回 <code>true</code> 或 <code>false</code>。</span></p> +<p><code><strong>startsWith()</strong></code> 方法用来判断当前字符串是否以另外一个给定的子字符串开头,并根据判断结果返回 <code>true</code> 或 <code>false</code>。</p> <div>{{EmbedInteractiveExample("pages/js/string-startswith.html")}}</div> diff --git a/files/zh-cn/web/javascript/reference/global_objects/string/substr/index.html b/files/zh-cn/web/javascript/reference/global_objects/string/substr/index.html index 8faa458218..782816ee91 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/string/substr/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/string/substr/index.html @@ -19,7 +19,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/String/substr <dl> <dt><code>start</code></dt> - <dd>开始提取字符的位置。如果为负值,则被看作 <code style="font-style: normal; line-height: 1.5;">strLength + </code><code style="font-style: normal; line-height: 1.5;">start,其中</code><span style="line-height: 1.5;"> </span><code style="font-style: normal; line-height: 1.5;">strLength</code><span style="line-height: 1.5;"> 为字符串的长度(例如,如果 <code>start</code> 为 <code>-3,则被看作</code> <code>strLength + (-3))。</code></span></dd> + <dd>开始提取字符的位置。如果为负值,则被看作 <code style="font-style: normal; line-height: 1.5;">strLength + </code><code style="font-style: normal; line-height: 1.5;">start,其中</code> <code style="font-style: normal; line-height: 1.5;">strLength</code> 为字符串的长度(例如,如果 <code>start</code> 为 <code>-3,则被看作</code> <code>strLength + (-3))。</code></dd> </dl> <dl> diff --git a/files/zh-cn/web/javascript/reference/global_objects/string/substring/index.html b/files/zh-cn/web/javascript/reference/global_objects/string/substring/index.html index 9a2d97f935..e2b061d1a3 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/string/substring/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/string/substring/index.html @@ -105,7 +105,7 @@ replaceString("World", "Web", "Brave New World");</pre> return fullS.split(oldS).join(newS); }</pre> -<p><span style="line-height: 1.5;">上面的代码只是子字符串操作的一个例子。如果你需要替换子字符串,更多时候会用到 </span><span style="line-height: 1.5em;">{{jsxref("String.prototype.replace()")}}。</span></p> +<p>上面的代码只是子字符串操作的一个例子。如果你需要替换子字符串,更多时候会用到 {{jsxref("String.prototype.replace()")}}。</p> <h2 id="规范">规范</h2> diff --git a/files/zh-cn/web/javascript/reference/global_objects/string/tolowercase/index.html b/files/zh-cn/web/javascript/reference/global_objects/string/tolowercase/index.html index e08a47bb55..b0ecb92a51 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/string/tolowercase/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/string/tolowercase/index.html @@ -40,7 +40,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/String/toLowerCase <div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; line-height: inherit; top: 0px; background: 0px 0px;"></div> -<p><font face="x-locale-heading-primary, zillaslab, Palatino, Palatino Linotype, x-locale-heading-secondary, serif"><span style="font-size: 37.33327865600586px;"><strong>说明</strong></span></font></p> +<p><font face="x-locale-heading-primary, zillaslab, Palatino, Palatino Linotype, x-locale-heading-secondary, serif"><strong>说明</strong></font></p> diff --git a/files/zh-cn/web/javascript/reference/global_objects/symbol/index.html b/files/zh-cn/web/javascript/reference/global_objects/symbol/index.html index 3299f33a71..346c6df0f0 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/symbol/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/symbol/index.html @@ -45,7 +45,7 @@ var sym3 = Symbol('foo'); <pre class="brush: js notranslate">var sym = new Symbol(); // TypeError</pre> -<p>这会阻止创建一个显式的 Symbol 包装器对象而不是一个 Symbol 值。围绕原始数据类型创建一个显式包装器对象从 ECMAScript 6 开始不再被支持。 然而,现有的原始包装器对象,如 <code style="font-style: normal;">new Boolean</code>、<code style="font-style: normal;">new String</code>以及<span style="font-family: consolas,monaco,andale mono,monospace;"><code>new Number</code>,因为遗留原因仍可被创建。</span></p> +<p>这会阻止创建一个显式的 Symbol 包装器对象而不是一个 Symbol 值。围绕原始数据类型创建一个显式包装器对象从 ECMAScript 6 开始不再被支持。 然而,现有的原始包装器对象,如 <code style="font-style: normal;">new Boolean</code>、<code style="font-style: normal;">new String</code>以及<code>new Number</code>,因为遗留原因仍可被创建。</p> <p>如果你真的想创建一个 <u>Symbol 包装器对象 </u>(<code>Symbol wrapper object</code>),你可以使用 <code>Object()</code> 函数:</p> @@ -150,9 +150,9 @@ typeof symObj; // "object"</pre> <p> {{jsxref("Operators/typeof", "typeof")}}运算符能帮助你识别 symbol 类型</p> -<pre class="brush: js notranslate"><code class="language-js"><span class="keyword token">typeof</span> <span class="function token">Symbol<span class="punctuation token">(</span></span><span class="punctuation token">)</span> <span class="operator token">==</span><span class="operator token">=</span> <span class="string token">'symbol'</span> -<span class="keyword token">typeof</span> <span class="function token">Symbol<span class="punctuation token">(</span></span><span class="string token">'foo'</span><span class="punctuation token">)</span> <span class="operator token">==</span><span class="operator token">=</span> <span class="string token">'symbol'</span> -<span class="keyword token">typeof</span> Symbol<span class="punctuation token">.</span>iterator <span class="operator token">==</span><span class="operator token">=</span> <span class="string token">'symbol'</span></code> +<pre class="brush: js notranslate"><code class="language-js">typeof Symbol() === 'symbol' +typeof Symbol('foo') === 'symbol' +typeof Symbol.iterator === 'symbol'</code> </pre> <h3 id="Symbol_类型转换">Symbol 类型转换</h3> @@ -170,23 +170,23 @@ typeof symObj; // "object"</pre> <p>Symbols 在 <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...in"><code>for...in</code></a> 迭代中不可枚举。另外,{{jsxref("Object.getOwnPropertyNames()")}} 不会返回 symbol 对象的属性,但是你能使用 {{jsxref("Object.getOwnPropertySymbols()")}} 得到它们。</p> -<pre class="brush: js line-numbers language-js notranslate"><code class="language-js"><span class="keyword token">var</span> obj <span class="operator token">=</span> <span class="punctuation token">{</span><span class="punctuation token">}</span><span class="punctuation token">;</span> +<pre class="brush: js line-numbers language-js notranslate"><code class="language-js">var obj = {}; -obj<span class="punctuation token">[</span><span class="function token">Symbol</span><span class="punctuation token">(</span><span class="string token">"a"</span><span class="punctuation token">)</span><span class="punctuation token">]</span> <span class="operator token">=</span> <span class="string token">"a"</span><span class="punctuation token">;</span> -obj<span class="punctuation token">[</span>Symbol<span class="punctuation token">.</span><span class="keyword token">for</span><span class="punctuation token">(</span><span class="string token">"b"</span><span class="punctuation token">)</span><span class="punctuation token">]</span> <span class="operator token">=</span> <span class="string token">"b"</span><span class="punctuation token">;</span> -obj<span class="punctuation token">[</span><span class="string token">"c"</span><span class="punctuation token">]</span> <span class="operator token">=</span> <span class="string token">"c"</span><span class="punctuation token">;</span> -obj<span class="punctuation token">.</span>d <span class="operator token">=</span> <span class="string token">"d"</span><span class="punctuation token">;</span> +obj[Symbol("a")] = "a"; +obj[Symbol.for("b")] = "b"; +obj["c"] = "c"; +obj.d = "d"; -<span class="keyword token">for</span> <span class="punctuation token">(</span><span class="keyword token">var</span> i <span class="keyword token">in</span> obj<span class="punctuation token">)</span> <span class="punctuation token">{</span> - console<span class="punctuation token">.</span><span class="function token">log</span><span class="punctuation token">(</span>i<span class="punctuation token">)</span><span class="punctuation token">;</span> <span class="comment token">// logs "c" and "d"</span> -<span class="punctuation token">}</span></code></pre> +for (var i in obj) { + console.log(i); // logs "c" and "d" +}</code></pre> <h3 id="Symbols_与_JSON.stringify">Symbols 与 <code>JSON.stringify()</code></h3> <p>当使用 JSON.stringify() 时,以 symbol 值作为键的属性会被完全忽略:</p> -<pre class="brush: js notranslate"><code class="language-js">JSON<span class="punctuation token">.</span><span class="function token">stringify</span><span class="punctuation token">(</span><span class="punctuation token">{</span><span class="punctuation token">[</span><span class="function token">Symbol</span><span class="punctuation token">(</span><span class="string token">"foo"</span><span class="punctuation token">)</span><span class="punctuation token">]</span><span class="punctuation token">:</span> <span class="string token">"foo"</span><span class="punctuation token">}</span><span class="punctuation token">)</span><span class="punctuation token">;</span> -<span class="comment token">// '{}'</span></code></pre> +<pre class="brush: js notranslate"><code class="language-js">JSON.stringify({[Symbol("foo")]: "foo"}); +// '{}'</code></pre> <p>更多细节,请看 {{jsxref("JSON.stringify()")}}。</p> @@ -194,10 +194,10 @@ obj<span class="punctuation token">.</span>d <span class="operator token">=</spa <p>当一个 Symbol 包装器对象作为一个属性的键时,这个对象将被强制转换为它包装过的 symbol 值:</p> -<pre class="brush: js notranslate"><code class="language-js"><span class="keyword token">var</span> sym <span class="operator token">=</span> <span class="function token">Symbol</span><span class="punctuation token">(</span><span class="string token">"foo"</span><span class="punctuation token">)</span><span class="punctuation token">;</span> -<span class="keyword token">var</span> obj <span class="operator token">=</span> <span class="punctuation token">{</span><span class="punctuation token">[</span>sym<span class="punctuation token">]</span><span class="punctuation token">:</span> <span class="number token">1</span><span class="punctuation token">}</span><span class="punctuation token">;</span> -obj<span class="punctuation token">[</span>sym<span class="punctuation token">]</span><span class="punctuation token">;</span> <span class="comment token">// 1</span> -obj<span class="punctuation token">[</span><span class="function token">Object</span><span class="punctuation token">(</span>sym<span class="punctuation token">)</span><span class="punctuation token">]</span><span class="punctuation token">;</span> <span class="comment token">// still 1</span></code></pre> +<pre class="brush: js notranslate"><code class="language-js">var sym = Symbol("foo"); +var obj = {[sym]: 1}; +obj[sym]; // 1 +obj[Object(sym)]; // still 1</code></pre> <h2 id="规范">规范</h2> diff --git a/files/zh-cn/web/javascript/reference/global_objects/symbol/iterator/index.html b/files/zh-cn/web/javascript/reference/global_objects/symbol/iterator/index.html index a765dac7c7..ff58e52170 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/symbol/iterator/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/symbol/iterator/index.html @@ -18,7 +18,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Symbol/iterator <p>当需要对一个对象进行迭代时(<font><font>比如开始用于一个</font></font><code><font><font>for..of</font></font></code><font><font>循环中</font></font>),它的<code>@@iterator</code>方法都会在不传参情况下被调用,返回的<strong>迭代器</strong>用于获取要迭代的值。</p> -<p>一些内置类型拥有默认的迭代器行为,其他类型(如 {{jsxref("Object")}})则没有。下表中的内置类型拥有默认的<span style="font-family: consolas,monaco,andale mono,monospace;"><code>@@iterator</code></span>方法:</p> +<p>一些内置类型拥有默认的迭代器行为,其他类型(如 {{jsxref("Object")}})则没有。下表中的内置类型拥有默认的<code>@@iterator</code>方法:</p> <ul> <li>{{jsxref("Array.@@iterator", "Array.prototype[@@iterator]()")}}</li> diff --git a/files/zh-cn/web/javascript/reference/global_objects/syntaxerror/index.html b/files/zh-cn/web/javascript/reference/global_objects/syntaxerror/index.html index fed587b744..27e66ef381 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/syntaxerror/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/syntaxerror/index.html @@ -28,7 +28,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/SyntaxError <dt><code>fileName</code> {{non-standard_inline}}</dt> <dd>可选的. 包含引发异常的代码的文件名</dd> <dt><code>lineNumber</code> {{non-standard_inline}}</dt> - <dd><span style="line-height: 19.0909080505371px;">可选的</span>. <span style="line-height: 19.0909080505371px;">包含引发异常的代码</span><span style="line-height: 19.0909080505371px;">的行号</span></dd> + <dd>可选的. 包含引发异常的代码的行号</dd> </dl> <h2 id="Properties" name="Properties">属性</h2> @@ -50,7 +50,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/SyntaxError <h3 id="Methods_of_SyntaxError_instances" name="Methods_of_SyntaxError_instances">方法</h3> -<div>{{page('/<span style="line-height: 19.0909080505371px;">zh-CN</span>/docs/Web/JavaScript/Reference/Global_Objects/SyntaxError/prototype', '方法')}}</div> +<div>{{page('/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/SyntaxError/prototype', '方法')}}</div> <h2 id="Examples" name="Examples">示例</h2> diff --git a/files/zh-cn/web/javascript/reference/global_objects/typedarray/bytes_per_element/index.html b/files/zh-cn/web/javascript/reference/global_objects/typedarray/bytes_per_element/index.html index 4418eb2aab..c49ee169ba 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/typedarray/bytes_per_element/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/typedarray/bytes_per_element/index.html @@ -43,7 +43,7 @@ Float64Array.BYTES_PER_ELEMENT; // 8</pre> <tr> <td><a href="https://www.khronos.org/registry/typedarray/specs/latest/#7">Typed Array Specification</a></td> <td>已过期</td> - <td><span><span>被ECMAScript 6取代</span></span></td> + <td>被ECMAScript 6取代</td> </tr> <tr> <td>{{SpecName('ES6', '#sec-typedarray.bytes_per_element', 'TypedArray.BYTES_PER_ELEMENT')}}</td> diff --git a/files/zh-cn/web/javascript/reference/global_objects/typedarray/index.html b/files/zh-cn/web/javascript/reference/global_objects/typedarray/index.html index 9be826cd36..b3f9275b6d 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/typedarray/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/typedarray/index.html @@ -194,11 +194,11 @@ Int8Array.prototype.foo = "bar"; </tbody> </table> -<h2 id="属性"><span style='font-family: x-locale-heading-primary,zillaslab,Palatino,"Palatino Linotype",x-locale-heading-secondary,serif; font-size: 2.33333rem; letter-spacing: -0.00278rem;'>属性</span></h2> +<h2 id="属性">属性</h2> <dl> <dt>{{jsxref("TypedArray.BYTES_PER_ELEMENT")}}</dt> - <dd>返回一个数值,代表不同类型的类型化数组对象中,单个元素的字节大小。例如 <code>new Int8Array().BYTES_PER_ELEMENT === 1</code>, <font face="consolas, Liberation Mono, courier, monospace"><span style="background-color: rgba(220, 220, 220, 0.5);"><code>new Int16Array().BYTES_PER_ELEMENT === 2</code></span></font> ( 8 位字节为 1,16 位为 2 字节,类推)。 </dd> + <dd>返回一个数值,代表不同类型的类型化数组对象中,单个元素的字节大小。例如 <code>new Int8Array().BYTES_PER_ELEMENT === 1</code>, <font face="consolas, Liberation Mono, courier, monospace"><code>new Int16Array().BYTES_PER_ELEMENT === 2</code></font> ( 8 位字节为 1,16 位为 2 字节,类推)。 </dd> <dt><code><em>TypedArray</em>.length</code></dt> <dd>类型化数组中元素的个数,例如 <code>new Int8Array(3).length === 3</code>。</dd> <dt>{{jsxref("TypedArray.name")}}</dt> @@ -275,7 +275,7 @@ for (var k in typedArrayTypes) <h2 id="浏览器支持">浏览器支持</h2> -<p><span style='background-color: transparent; color: #333333; display: inline !important; float: none; font-family: "Open Sans",arial,x-locale-body,sans-serif; font-size: 16px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; white-space: normal;'>{{Compat("javascript.builtins.TypedArray")}}</span></p> +<p>{{Compat("javascript.builtins.TypedArray")}}</p> <h2 id="兼容性注意事项">兼容性注意事项</h2> diff --git a/files/zh-cn/web/javascript/reference/global_objects/typedarray/some/index.html b/files/zh-cn/web/javascript/reference/global_objects/typedarray/some/index.html index 2da4a21a65..4c285a5fe1 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/typedarray/some/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/typedarray/some/index.html @@ -49,7 +49,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/TypedArray/some <p><code>some</code> 被调用不会改变 typed array .</p> -<h3 class="highlight-spanned" id="示例"><span class="highlight-span">示例</span></h3> +<h3 class="highlight-spanned" id="示例">示例</h3> <h3 id="Testing_size_of_all_typed_array_elements">Testing size of all typed array elements</h3> diff --git a/files/zh-cn/web/javascript/reference/global_objects/uint16array/index.html b/files/zh-cn/web/javascript/reference/global_objects/uint16array/index.html index 7816a7642e..aac0ee3cbc 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/uint16array/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/uint16array/index.html @@ -5,7 +5,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Uint16Array --- <div>{{JSRef}}</div> -<p><code><font face="Arial, x-locale-body, sans-serif"><span style="background-color: #ffffff;">该 </span></font><strong>Uint16Array</strong></code> 类型数组表示16位无符号整数,按平台字节顺序排列。如果需要控制字节顺序,请使用 DataView 代替。内容被初始化为0。建立后,就可以使用对象的方法或使用标准数组索引语法(即使用括号表示法)引用数组中的元素。</p> +<p><code><font face="Arial, x-locale-body, sans-serif">该 </font><strong>Uint16Array</strong></code> 类型数组表示16位无符号整数,按平台字节顺序排列。如果需要控制字节顺序,请使用 DataView 代替。内容被初始化为0。建立后,就可以使用对象的方法或使用标准数组索引语法(即使用括号表示法)引用数组中的元素。</p> <h2 id="构造函数">构造函数</h2> diff --git a/files/zh-cn/web/javascript/reference/global_objects/uint8array/index.html b/files/zh-cn/web/javascript/reference/global_objects/uint8array/index.html index 1619a2abb3..42345aaf89 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/uint8array/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/uint8array/index.html @@ -158,7 +158,7 @@ var uint8 = new Uint8Array(iterable); <tr> <td><a href="https://www.khronos.org/registry/typedarray/specs/latest/#7">类型化数组规范</a></td> <td>Obsolete</td> - <td><span><span>由 ECMAScript 6 取代。</span></span></td> + <td>由 ECMAScript 6 取代。</td> </tr> <tr> <td>{{SpecName('ES6', '#table-45', 'TypedArray constructors')}}</td> diff --git a/files/zh-cn/web/javascript/reference/global_objects/undefined/index.html b/files/zh-cn/web/javascript/reference/global_objects/undefined/index.html index 71a33f157d..20ff8d53a7 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/undefined/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/undefined/index.html @@ -101,9 +101,9 @@ if(y === undefined) { // ReferenceError: y is not defined <p>但是,技术方面看来这样的使用方法应该被避免。JavaScript是一个静态作用域语言,所以,一个变量是否被声明可以通过看它是否在一个封闭的上下文中被声明。唯一的例外是全局作用域,但是全局作用域是被绑定在全局对象上的,所以要检查一个变量是否在全局上下文中存在可以通过检查全局对象上是否存在这个属性(比如使用{{jsxref("Operators/in", "in")}}操作符)。</p> -<pre class="brush: js line-numbers language-js"><code class="language-js"><span class="keyword token">if</span> <span class="punctuation token">(</span><span class="string token">'x'</span> <span class="keyword token">in</span> window<span class="punctuation token">)</span> <span class="punctuation token">{</span> - <span class="comment token">// 只有x被全局性的定义 才会这行这些语句</span> -<span class="punctuation token">}</span></code></pre> +<pre class="brush: js line-numbers language-js"><code class="language-js">if ('x' in window) { + // 只有x被全局性的定义 才会这行这些语句 +}</code></pre> <h3 id="Void操作符和undefined">Void操作符和undefined</h3> diff --git a/files/zh-cn/web/javascript/reference/global_objects/weakmap/get/index.html b/files/zh-cn/web/javascript/reference/global_objects/weakmap/get/index.html index 5dd596c3ff..39357eb6e4 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/weakmap/get/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/weakmap/get/index.html @@ -20,7 +20,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/WeakMap/get <h3 id="返回值">返回值</h3> -<h3 id="返回与指定键相关联的值,如果_WeakMap_对象找不到这个键则返回_undefined。"><span style="font-size: 14px; line-height: 1.5;">返回与指定键相关联的值,如果 </span><code style="font-size: 14px; font-style: normal; font-weight: normal; line-height: 1.5;">WeakMap</code><span style="font-size: 14px; line-height: 1.5;"> 对象找不到这个键则返回 </span><code style="font-size: 14px; font-style: normal; font-weight: normal; line-height: 1.5;">undefined</code><span style="font-size: 14px; line-height: 1.5;">。</span></h3> +<h3 id="返回与指定键相关联的值,如果_WeakMap_对象找不到这个键则返回_undefined。">返回与指定键相关联的值,如果 <code style="font-size: 14px; font-style: normal; font-weight: normal; line-height: 1.5;">WeakMap</code> 对象找不到这个键则返回 <code style="font-size: 14px; font-style: normal; font-weight: normal; line-height: 1.5;">undefined</code>。</h3> <h2 id="例子">例子</h2> diff --git a/files/zh-cn/web/javascript/reference/global_objects/weakset/index.html b/files/zh-cn/web/javascript/reference/global_objects/weakset/index.html index 3e04c8ff98..1e82a11d54 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/weakset/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/weakset/index.html @@ -94,7 +94,7 @@ execRecursively(obj => console.log(obj), foo);</pre> <dt><code>WeakSet.length</code></dt> <dd><code>length</code> 属性的值为 0.</dd> <dt>{{jsxref("WeakSet.prototype")}}</dt> - <dd><span>表示<code>WeakSet</code>构造函数的原型。 允许向所有<code>WeakSet</code>对象添加属性。</span></dd> + <dd>表示<code>WeakSet</code>构造函数的原型。 允许向所有<code>WeakSet</code>对象添加属性。</dd> </dl> <h2 id="Boolean_instances" name="Boolean_instances"><code>WeakSet</code> 实例</h2> diff --git a/files/zh-cn/web/javascript/reference/global_objects/webassembly/compileerror/index.html b/files/zh-cn/web/javascript/reference/global_objects/webassembly/compileerror/index.html index 179b8589a2..9292349082 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/webassembly/compileerror/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/webassembly/compileerror/index.html @@ -15,7 +15,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/WebAssembly/CompileError <dl> <dt><code>message</code> {{optional_inline}}</dt> - <dd><span class="tlid-translation translation" lang="zh-CN"><span title="">有可读性的错误描述。</span></span></dd> + <dd>有可读性的错误描述。</dd> <dt><code>fileName</code> {{optional_inline}}{{non-standard_inline}}</dt> <dd>包含导致异常的代码的文件名。</dd> <dt><code>lineNumber</code> {{optional_inline}}{{non-standard_inline}}</dt> diff --git a/files/zh-cn/web/javascript/reference/global_objects/webassembly/index.html b/files/zh-cn/web/javascript/reference/global_objects/webassembly/index.html index 66f14793af..87978a0016 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/webassembly/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/webassembly/index.html @@ -63,10 +63,10 @@ translation_of: Web/JavaScript/Reference/Global_Objects/WebAssembly <p>下面的示例(请参见GitHub上的<a href="https://github.com/mdn/webassembly-examples/blob/master/js-api-examples/instantiate-streaming.html">Instantiate-streaming.html</a>演示,并查看<a href="https://mdn.github.io/webassembly-examples/js-api-examples/instantiate-streaming.html">在线演示</a>)直接从流式底层源传输.wasm模块,然后对其进行编译和实例化,并通过<code>ResultObject</code>实现promise。 由于<code>instantiateStreaming()</code>函数接受对 {{domxref("Response")}} 对象的promise,因此您可以直接向其传递{{domxref("WindowOrWorkerGlobalScope.fetch()")}}调用,然后它将把返回的response传递给随后的函数。</p> -<pre class="brush: js line-numbers language-js"><code class="language-js"><span class="keyword token">var</span> importObject <span class="operator token">=</span> <span class="punctuation token">{</span> imports<span class="punctuation token">:</span> <span class="punctuation token">{</span> <span class="function function-variable token">imported_func</span><span class="punctuation token">:</span> <span class="parameter token">arg</span> <span class="operator token">=></span> console<span class="punctuation token">.</span><span class="function token">log</span><span class="punctuation token">(</span>arg<span class="punctuation token">)</span> <span class="punctuation token">}</span> <span class="punctuation token">}</span><span class="punctuation token">;</span> +<pre class="brush: js line-numbers language-js"><code class="language-js">var importObject = { imports: { imported_func: arg => console.log(arg) } }; -WebAssembly<span class="punctuation token">.</span><span class="function token">instantiateStreaming</span><span class="punctuation token">(</span><span class="function token">fetch</span><span class="punctuation token">(</span><span class="string token">'simple.wasm'</span><span class="punctuation token">)</span><span class="punctuation token">,</span> importObject<span class="punctuation token">)</span> -<span class="punctuation token">.</span><span class="function token">then</span><span class="punctuation token">(</span><span class="parameter token">obj</span> <span class="operator token">=></span> obj<span class="punctuation token">.</span>instance<span class="punctuation token">.</span>exports<span class="punctuation token">.</span><span class="function token">exported_func</span><span class="punctuation token">(</span><span class="punctuation token">)</span><span class="punctuation token">)</span></code></pre> +WebAssembly.instantiateStreaming(fetch('simple.wasm'), importObject) +.then(obj => obj.instance.exports.exported_func())</code></pre> <p>返回的<code>ResultObject</code>实例的成员可以被随后访问到,可以调用实例中被导出的方法。</p> |