--- title: 'get RegExp[@@species]' slug: Web/JavaScript/Reference/Global_Objects/RegExp/@@species translation_of: Web/JavaScript/Reference/Global_Objects/RegExp/@@species ---
RegExp[@@species]
访问器属性返回RegExp
的构造器。
RegExp[Symbol.species]
species
访问器属性返回 RegExp
对象的默认构造器。子类构造器可能会覆盖它,来修改构造器的指派。
species
属性返回默认构造器函数,它是用于RegExp
对象的RegExp
构造器:
RegExp[Symbol.species]; // 函数 RegExp()
在派生的正则类(也就是你自定义的正则类 MyRegExp
)中,MyRegExp
的 species 是 MyRegExp
构造器。但是,你可能希望覆盖它,以便在你的派生类方法中,返回 RegExp
父类对象:
class MyRegExp extends RegExp { // 将 MyRegExp species 覆盖为 RegExp 父类构造器 static get [Symbol.species]() { return RegExp; } }
Specification | Status | Comment |
---|---|---|
{{SpecName('ES6', '#sec-get-regexp-@@species', 'get RegExp [ @@species ]')}} | {{Spec2('ES6')}} | 初始定义。 |
{{SpecName('ESDraft', '#sec-get-regexp-@@species', 'get RegExp [ @@species ]')}} | {{Spec2('ESDraft')}} |
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Basic support | {{CompatUnknown}} | {{CompatGeckoDesktop("49")}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} |
Feature | Android | Chrome for Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|
Basic support | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatGeckoMobile("49")}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} |