Baseline Widely available
Symbol.split
æåä¸ä¸ªæ£å表达å¼çç´¢å¼å¤åå²åç¬¦ä¸²çæ¹æ³ãè¿ä¸ªæ¹æ³éè¿ String.prototype.split()
è°ç¨ã
详æ
请åé
RegExp.prototype[Symbol.split]()
å String.prototype.split()
ã
class Split1 {
constructor(value) {
this.value = value;
}
[Symbol.split](string) {
const index = string.indexOf(this.value);
return `${this.value}${string.substring(0, index)}/${string.substring(
index + this.value.length,
)}`;
}
}
console.log("foobar".split(new Split1("foo")));
// Expected output: "foo/bar"
å¼
å
ç½®éç¨ç¬¦å· Symbol.split
ã
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" ]
è§è æµè§å¨å
¼å®¹æ§ åé
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4