aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/javascript/reference/global_objects/array/@@species/index.html
diff options
context:
space:
mode:
authorPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
committerPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
commit33058f2b292b3a581333bdfb21b8f671898c5060 (patch)
tree51c3e392513ec574331b2d3f85c394445ea803c6 /files/zh-cn/web/javascript/reference/global_objects/array/@@species/index.html
parent8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff)
downloadtranslated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip
initial commit
Diffstat (limited to 'files/zh-cn/web/javascript/reference/global_objects/array/@@species/index.html')
-rw-r--r--files/zh-cn/web/javascript/reference/global_objects/array/@@species/index.html78
1 files changed, 78 insertions, 0 deletions
diff --git a/files/zh-cn/web/javascript/reference/global_objects/array/@@species/index.html b/files/zh-cn/web/javascript/reference/global_objects/array/@@species/index.html
new file mode 100644
index 0000000000..cc87927e5e
--- /dev/null
+++ b/files/zh-cn/web/javascript/reference/global_objects/array/@@species/index.html
@@ -0,0 +1,78 @@
+---
+title: 'get Array[@@species]'
+slug: Web/JavaScript/Reference/Global_Objects/Array/@@species
+tags:
+ - JavaScript
+ - 原型
+ - 数组
+ - 方法
+translation_of: Web/JavaScript/Reference/Global_Objects/Array/@@species
+---
+<div>{{JSRef}}</div>
+
+<p><code><strong>Array[@@species]</strong></code> 访问器属性返回 <code>Array</code> 的构造函数。</p>
+
+<h2 id="语法">语法</h2>
+
+<pre class="syntaxbox">Array[Symbol.species]
+</pre>
+
+<h3 id="返回值">返回值</h3>
+
+<p>{{jsxref("Array")}} 的构造函数。</p>
+
+<h2 id="描述">描述</h2>
+
+<p><code>species</code> 访问器属性返回 <code>Array</code> 对象的默认构造函数。子类的构造函数可能会覆盖并改变构造函数的赋值。</p>
+
+<h2 id="示例">示例</h2>
+
+<p><code>species</code> 属性返回默认构造函数, 它用于 <code>Array</code> 对象的构造函数 <code>Array</code>:</p>
+
+<pre class="brush: js">Array[Symbol.species]; // function Array()</pre>
+
+<p>在继承类的对象中(例如你自定义的数组 <code>MyArray</code>),<code>MyArray</code> 的 <code>species</code> 属性返回的是 <code>MyArray</code> 这个构造函数. 然而你可能想要覆盖它,以便在你继承的对象 <code>MyArray</code> 中返回父类的构造函数 <code>Array</code> :</p>
+
+<pre class="brush: js">class MyArray extends Array {
+ // 重写 MyArray 的 species 属性到父类 Array 的构造函数
+ static get [Symbol.species]() { return Array; }
+}</pre>
+
+<h2 id="规范">规范</h2>
+
+<table class="standard-table">
+ <tbody>
+ <tr>
+ <th scope="col">规范</th>
+ <th scope="col">状态</th>
+ <th scope="col">备注</th>
+ </tr>
+ <tr>
+ <td>{{SpecName('ES6', '#sec-get-array-@@species', 'get Array [ @@species ]')}}</td>
+ <td>{{Spec2('ES6')}}</td>
+ <td>Initial definition.</td>
+ </tr>
+ <tr>
+ <td>{{SpecName('ESDraft', '#sec-get-array-@@species', 'get Array [ @@species ]')}}</td>
+ <td>{{Spec2('ESDraft')}}</td>
+ <td></td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="浏览器兼容性">浏览器兼容性</h2>
+
+<div>
+<div>
+
+
+<p>{{Compat("javascript.builtins.Array.@@species")}}</p>
+</div>
+</div>
+
+<h2 id="参见">参见</h2>
+
+<ul>
+ <li>{{jsxref("Array")}}</li>
+ <li>{{jsxref("Symbol.species")}}</li>
+</ul>