Baseline Widely available
Die statische Dateneigenschaft Symbol.split
repräsentiert das bekannte Symbol Symbol.split
. Die Methode String.prototype.split()
sucht dieses Symbol im ersten Argument für die Methode, die einen String an den Indizes aufteilt, die mit dem aktuellen Objekt übereinstimmen.
Für mehr Informationen siehe RegExp.prototype[Symbol.split]()
und 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"
Wert
Das bekannte Symbol 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" ]
Spezifikationen Browser-Kompatibilität Siehe auch MDN-Feedback-Box War diese Ãbersetzung hilfreich?
Diese Seite wurde automatisch aus dem Englischen übersetzt.
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