aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/javascript/reference/global_objects/symbol/split/index.html
blob: 53b98d57cdc1c7487c5c171fff6e49b8e5768c50 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
---
title: Symbol.split
slug: Web/JavaScript/Reference/Global_Objects/Symbol/split
translation_of: Web/JavaScript/Reference/Global_Objects/Symbol/split
---
<div>{{JSRef}}</div>

<p><code><strong>Symbol.split</strong></code> 指向 一个正则表达式的索引处分割字符串的方法。 这个方法通过 {{jsxref("String.prototype.split()")}} 调用。</p>

<p>详情请参阅{{jsxref("RegExp.@@split", "RegExp.prototype[@@split]()")}}{{jsxref("String.prototype.split()")}}.</p>

<div>{{EmbedInteractiveExample("pages/js/symbol-split.html")}}</div>

<div class="hidden">The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone <a href="https://github.com/mdn/interactive-examples">https://github.com/mdn/interactive-examples</a> and send us a pull request.</div>

<div>{{js_property_attributes(0,0,0)}}</div>

<h2 id="示例">示例</h2>

<p>[Symbol.split]指向‘aba’.split(/a/)</p>

<pre class="brush: js notranslate">/a/[Symbol.split]('aba',3)</pre>

<p>"dayinlove".split(exp)调用[Symbol.split](str)处理,并把实参"dayinlove"传给形参str</p>

<pre class="brush: js notranslate">var exp =  {
        pat:'in',
        [Symbol.split](str) {
          return str.split(this.pat);
          }
    }

    "dayinlove".split(exp);
//["day", "love"]</pre>

<h2 id="技术标准">技术标准</h2>

<table class="standard-table">
 <tbody>
  <tr>
   <th scope="col">文档</th>
   <th scope="col">状态</th>
   <th scope="col">备注</th>
  </tr>
  <tr>
   <td>{{SpecName('ES6', '#sec-symbol.split', 'Symbol.split')}}</td>
   <td>{{Spec2('ES6')}}</td>
   <td>初始定义.</td>
  </tr>
  <tr>
   <td>{{SpecName('ESDraft', '#sec-symbol.split', 'Symbol.split')}}</td>
   <td>{{Spec2('ESDraft')}}</td>
   <td></td>
  </tr>
 </tbody>
</table>

<h2 id="浏览器兼容性">浏览器兼容性</h2>

<p>{{CompatibilityTable}}</p>

<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>{{CompatChrome(50)}}</td>
   <td>{{ CompatGeckoDesktop(49) }}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</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>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
   <td>{{ CompatGeckoMobile(49) }}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
  </tr>
 </tbody>
</table>
</div>

<h2 id="参阅">参阅</h2>

<ul>
 <li>{{jsxref("Symbol.match")}}</li>
 <li>{{jsxref("Symbol.replace")}}</li>
 <li>{{jsxref("Symbol.search")}}</li>
 <li>{{jsxref("RegExp.@@split", "RegExp.prototype[@@split]()")}}</li>
</ul>