Map.@@species
Map.@@species
Map[@@species]
访问器属性会返回一个 Map
构造函数.
语法
Map[Symbol.species]
描述
species访问器属性返回了Map
对象的默认构造函数。子类的构造函数会重载它来改变构造函数的分配。
示例
该species属性返回了默认的构造函数,是Map
用于构造Map
对象:
Map[Symbol.species]; // function Map()
在派生的集合对象(例如,自定义映射MyMap
)中,MyMap
species是MyMap
构造函数。不过,你可能想要覆盖这个,来返回Map
派生类方法中的父对象:
class MyMap extends Map {
// Overwrite MyMap species to the parent Map constructor
static get [Symbol.species]() { return Map; }
}
规范
Specification | Status | Comment |
---|---|---|
ECMAScript 2015 (6th Edition, ECMA-262)The definition of 'get Map @@species ' in that specification. | Standard | Initial definition. |
ECMAScript Latest Draft (ECMA-262)The definition of 'get Map @@species ' in that specification. | Draft | |
浏览器兼容性
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Basic support | No support | 41 (41) | No support | No support | No support |
Feature | Android | Chrome for Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|
Basic support | No support | No support | 41.0 (41) | No support | No support | No support |