Symbol.split

Symbol.split 静态数据属性代表 众所周知的符号 Symbol.splitString.prototype.split() 方法在其第一个参数上查找此符号,以查找在与当前对象匹配的索引处分割字符串的方法。

¥The Symbol.split static data property represents the well-known symbol Symbol.split. The String.prototype.split() method looks up this symbol on its first argument for the method that splits a string at the indices that match the current object.

有关详细信息,请参阅 RegExp.prototype[Symbol.split]()String.prototype.split()

¥For more information, seeRegExp.prototype[Symbol.split]() and String.prototype.split().

Try it

¥Value

众所周知的符号 Symbol.split

¥The well-known symbol Symbol.split.

Property attributes of Symbol.split
Writable no
Enumerable no
Configurable no

示例

¥Examples

定制反向分体

¥Custom reverse split

js
class ReverseSplit {
  [Symbol.split](string) {
    const array = string.split(" ");
    return array.reverse();
  }
}

console.log("Another one bites the dust".split(new ReverseSplit()));
// [ "dust", "the", "bites", "one", "Another" ]

规范

Specification
ECMAScript Language Specification
# sec-symbol.split

¥Specifications

浏览器兼容性

¥Browser compatibility

也可以看看