--- title: 'get Array[@@species]' slug: Web/JavaScript/Reference/Global_Objects/Array/@@species tags: - Array - JavaScript - Method - Prototype translation_of: Web/JavaScript/Reference/Global_Objects/Array/@@species ---
Array[@@species] アクセサープロパティは、Array コンストラクターを返します。
Array[Symbol.species]
{{jsxref("Array")}} コンストラクターです。
species アクセサープロパティは、 Array オブジェクトの既定のコンストラクターを返します。サブクラスのコンストラクターはコンストラクターに代入することで、これをオーバーライドすることができます。
species プロパティは、Array オブジェクトの既定のコンストラクター関数である Array コンストラクターを返します。
Array[Symbol.species]; // Array() 関数
派生コレクションオブジェクト (たとえば、独自の配列である MyArray) では、MyArray の species は MyArray コンストラクターです。しかし、派生クラスのメソッドで、親である Array オブジェクトを返すためにこれをオーバーライドしたいかもしれません。
class MyArrayBuffer extends ArrayBuffer {
// MyArray species を親である ArrayBuffer コンストラクタにオーバーライド。
static get [Symbol.species]() { return ArrayBuffer; }
}
| 仕様書 |
|---|
| {{SpecName('ESDraft', '#sec-get-array-@@species', 'get Array [ @@species ]')}} |
{{Compat("javascript.builtins.Array.@@species")}}