在线文档教程

Map.@@species

Map.@@species

Map[@@species] 访问器属性会返回一个 Map 构造函数.

语法

Map[Symbol.species]

描述

species访问器属性返回了Map对象的默认构造函数。子类的构造函数会重载它来改变构造函数的分配。

示例

该species属性返回了默认的构造函数,是Map用于构造Map对象:

Map[Symbol.species]; // function Map()

在派生的集合对象(例如,自定义映射MyMap)中,MyMapspecies是MyMap构造函数。不过,你可能想要覆盖这个,来返回Map派生类方法中的父对象:

class MyMap extends Map { // Overwrite MyMap species to the parent Map constructor static get [Symbol.species]() { return Map; } }

规范

SpecificationStatusComment
ECMAScript 2015 (6th Edition, ECMA-262)The definition of 'get Map @@species ' in that specification.StandardInitial definition.
ECMAScript Latest Draft (ECMA-262)The definition of 'get Map @@species ' in that specification.Draft

浏览器兼容性

FeatureChromeFirefox (Gecko)Internet ExplorerOperaSafari
Basic supportNo support41 (41)No supportNo supportNo support

FeatureAndroidChrome for AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Basic supportNo supportNo support41.0 (41)No supportNo supportNo support