diff options
Diffstat (limited to 'files/zh-cn/web/javascript/reference/global_objects/regexp/@@species')
-rw-r--r-- | files/zh-cn/web/javascript/reference/global_objects/regexp/@@species/index.html | 111 |
1 files changed, 111 insertions, 0 deletions
diff --git a/files/zh-cn/web/javascript/reference/global_objects/regexp/@@species/index.html b/files/zh-cn/web/javascript/reference/global_objects/regexp/@@species/index.html new file mode 100644 index 0000000000..49f72f06f7 --- /dev/null +++ b/files/zh-cn/web/javascript/reference/global_objects/regexp/@@species/index.html @@ -0,0 +1,111 @@ +--- +title: 'get RegExp[@@species]' +slug: Web/JavaScript/Reference/Global_Objects/RegExp/@@species +translation_of: Web/JavaScript/Reference/Global_Objects/RegExp/@@species +--- +<div>{{JSRef}}</div> + +<p><code><strong>RegExp[@@species]</strong></code> 访问器属性返回<code>RegExp</code> 的构造器。</p> + +<h2 id="语法">语法</h2> + +<pre class="syntaxbox">RegExp[Symbol.species] +</pre> + +<h2 id="描述">描述</h2> + +<p><code>species</code> 访问器属性返回 <code>RegExp</code> 对象的默认构造器。子类构造器可能会覆盖它,来修改构造器的指派。</p> + +<h2 id="示例">示例</h2> + +<p><code>species</code>属性返回默认构造器函数,它是用于<code>RegExp</code> 对象的<code>RegExp</code>构造器:</p> + +<pre class="brush: js">RegExp[Symbol.species]; // 函数 RegExp()</pre> + +<p>在派生的正则类(也就是你自定义的正则类 <code>MyRegExp</code>)中,<code>MyRegExp</code> 的 species 是 <code>MyRegExp</code> 构造器。但是,你可能希望覆盖它,以便在你的派生类方法中,返回 <code>RegExp</code> 父类对象:</p> + +<pre class="brush: js">class MyRegExp extends RegExp { + // 将 MyRegExp species 覆盖为 RegExp 父类构造器 + static get [Symbol.species]() { return RegExp; } +}</pre> + +<h2 id="规范">规范</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Specification</th> + <th scope="col">Status</th> + <th scope="col">Comment</th> + </tr> + <tr> + <td>{{SpecName('ES6', '#sec-get-regexp-@@species', 'get RegExp [ @@species ]')}}</td> + <td>{{Spec2('ES6')}}</td> + <td>初始定义。</td> + </tr> + <tr> + <td>{{SpecName('ESDraft', '#sec-get-regexp-@@species', 'get RegExp [ @@species ]')}}</td> + <td>{{Spec2('ESDraft')}}</td> + <td> </td> + </tr> + </tbody> +</table> + +<h2 id="浏览器兼容性">浏览器兼容性</h2> + +<div>{{CompatibilityTable}}</div> + +<div id="compat-desktop"> +<table class="compat-table"> + <tbody> + <tr> + <th>Feature</th> + <th>Chrome</th> + <th>Firefox (Gecko)</th> + <th>Internet Explorer</th> + <th>Opera</th> + <th>Safari</th> + </tr> + <tr> + <td>Basic support</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatGeckoDesktop("49")}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + </tr> + </tbody> +</table> +</div> + +<div id="compat-mobile"> +<table class="compat-table"> + <tbody> + <tr> + <th>Feature</th> + <th>Android</th> + <th>Chrome for Android</th> + <th>Firefox Mobile (Gecko)</th> + <th>IE Mobile</th> + <th>Opera Mobile</th> + <th>Safari Mobile</th> + </tr> + <tr> + <td>Basic support</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatGeckoMobile("49")}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + </tr> + </tbody> +</table> +</div> + +<h2 id="另见">另见</h2> + +<ul> + <li>{{jsxref("RegExp")}}</li> + <li>{{jsxref("Symbol.species")}}</li> +</ul> |