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"
æ¸è¾¼å¯è½ ä¸å¯ åæå¯è½ ä¸å¯ è¨å®å¯è½ ä¸å¯ ä¾ ç¬èªã®éæ¹åã®åå²
class ReverseSplit {
[Symbol.split](string) {
const array = string.split(" ");
return array.reverse();
}
}
console.log("Another one bites the dust".split(new ReverseSplit()));
// expected output: [ "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