--- 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>