Symbol.split
JavaScript Symbol.split属性
JavaScript
Symbol.split 符号用于在与正则表达式匹配的索引处拆分字符串。
语法
参数
字符串
返回值
从给定表达式中拆分出来的字符串
浏览器支持
浏览器 |
版本 |
Chrome |
32 |
Safari |
8 |
Firefox |
29 |
Opera |
19 |
示例
<script>
//JavaScript to illustrate Symbol.split
class Sp
{
constructor(value)
{
this.value = value;
}
[Symbol.split](string)
{
var index = string.indexOf(this.value);
return this.value;
}
}
document.write("We split huo from the string lidihuo<br>")
document.write('lidihuo'.split(new Sp('huo')));
//expected output:We split huo from the string lidihuo
//point
</script>
输出:
We split huo from the string lidihuo
huo