diff options
author | Irvin <irvinfly@gmail.com> | 2022-02-16 02:02:49 +0800 |
---|---|---|
committer | Irvin <irvinfly@gmail.com> | 2022-02-16 02:35:54 +0800 |
commit | 01b0e12ba27b5069248fd09235e9a7143915ee30 (patch) | |
tree | 0e9edf538dc3fa3331e1dbb79239b58186765f86 /files/zh-cn/web/javascript/reference/global_objects/array/from | |
parent | 6ca84f1794af830ada9736d7289ce29aabb04ca3 (diff) | |
download | translated-content-01b0e12ba27b5069248fd09235e9a7143915ee30.tar.gz translated-content-01b0e12ba27b5069248fd09235e9a7143915ee30.tar.bz2 translated-content-01b0e12ba27b5069248fd09235e9a7143915ee30.zip |
remove `notranslate` class in zh-CN
Diffstat (limited to 'files/zh-cn/web/javascript/reference/global_objects/array/from')
-rw-r--r-- | files/zh-cn/web/javascript/reference/global_objects/array/from/index.html | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/files/zh-cn/web/javascript/reference/global_objects/array/from/index.html b/files/zh-cn/web/javascript/reference/global_objects/array/from/index.html index 8cab100d7c..01b6062f91 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/array/from/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/array/from/index.html @@ -22,7 +22,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Array/from <h2 id="语法">语法</h2> -<pre class="syntaxbox notranslate">Array.from(<em>arrayLike</em>[, <em>mapFn</em>[, <em>thisArg</em>]]) +<pre class="syntaxbox">Array.from(<em>arrayLike</em>[, <em>mapFn</em>[, <em>thisArg</em>]]) </pre> <h3 id="参数">参数</h3> @@ -59,18 +59,18 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Array/from <h3 id="从_String_生成数组">从 <code>String</code> 生成数组</h3> -<pre class="brush: js notranslate">Array.from('foo'); +<pre class="brush: js">Array.from('foo'); // [ "f", "o", "o" ]</pre> <h3 id="从_Set_生成数组">从 <code>Set</code> 生成数组</h3> -<pre class="brush: js notranslate">const set = new Set(['foo', 'bar', 'baz', 'foo']); +<pre class="brush: js">const set = new Set(['foo', 'bar', 'baz', 'foo']); Array.from(set); // [ "foo", "bar", "baz" ]</pre> <h3 id="从_Map_生成数组">从 <code>Map</code> 生成数组</h3> -<pre class="brush: js notranslate">const map = new Map([[1, 2], [2, 4], [4, 8]]); +<pre class="brush: js">const map = new Map([[1, 2], [2, 4], [4, 8]]); Array.from(map); // [[1, 2], [2, 4], [4, 8]] @@ -84,7 +84,7 @@ Array.from(mapper.keys()); <h3 id="从类数组对象(arguments)生成数组">从类数组对象(arguments)生成数组</h3> -<pre class="brush: js notranslate">function f() { +<pre class="brush: js">function f() { return Array.from(arguments); } @@ -94,7 +94,7 @@ f(1, 2, 3); <h3 id="在_Array.from_中使用箭头函数">在 <code>Array.from</code> 中使用箭头函数</h3> -<pre class="brush: js notranslate">// Using an arrow function as the map function to +<pre class="brush: js">// Using an arrow function as the map function to // manipulate the elements Array.from([1, 2, 3], x => x + x); // [2, 4, 6] @@ -109,7 +109,7 @@ Array.from({length: 5}, (v, i) => i); <h3 id="序列生成器指定范围">序列生成器(指定范围)</h3> -<pre class="brush: js notranslate">// Sequence generator function (commonly referred to as "range", e.g. Clojure, PHP etc) +<pre class="brush: js">// Sequence generator function (commonly referred to as "range", e.g. Clojure, PHP etc) const range = (start, stop, step) => Array.from({ length: (stop - start) / step + 1}, (_, i) => start + (i * step)); // Generate numbers range 0..4 @@ -127,7 +127,7 @@ range('A'.charCodeAt(0), 'Z'.charCodeAt(0), 1).map(x => String.fromCharCode(x <h3 id="数组去重合并">数组去重合并</h3> -<pre class="brush: js notranslate">function combine(){ +<pre class="brush: js">function combine(){ let arr = [].concat.apply([], arguments); //没有去重复的新数组 return Array.from(new Set(arr)); } @@ -139,7 +139,7 @@ console.log(combine(m,n)); // [1, 2, 3]</pre> <p>ECMA-262 第六版标准中添加了 <code>Array.from </code>。有些实现中可能尚未包括在其中。你可以通过在脚本前添加如下内容作为替代方法,以使用未原生支持的 <code>Array.from</code> 方法。该算法按照 ECMA-262 第六版中的规范实现,并假定 <code>Object</code> 和 <code>TypeError</code> 有其本身的值, <code>callback.call</code> 对应 {{jsxref("Function.prototype.call")}} 。此外,鉴于无法使用 Polyfill 实现真正的的迭代器,该实现不支持规范中定义的泛型可迭代元素。</p> -<pre class="brush: js notranslate">// Production steps of ECMA-262, Edition 6, 22.1.2.1 +<pre class="brush: js">// Production steps of ECMA-262, Edition 6, 22.1.2.1 if (!Array.from) { Array.from = (function () { var toStr = Object.prototype.toString; |