Baseline Widely available
Die statische Dateneigenschaft Symbol.replace
repräsentiert das wohlbekannte Symbol Symbol.replace
. Die Methoden String.prototype.replace()
und String.prototype.replaceAll()
suchen dieses Symbol in ihrem ersten Argument, um die Methode zu finden, die Teilstrings ersetzt, die mit dem aktuellen Objekt übereinstimmen.
Für weitere Informationen siehe RegExp.prototype[Symbol.replace]()
, String.prototype.replace()
, und String.prototype.replaceAll()
.
class Replace1 {
constructor(value) {
this.value = value;
}
[Symbol.replace](string) {
return `s/${string}/${this.value}/g`;
}
}
console.log("foo".replace(new Replace1("bar")));
// Expected output: "s/foo/bar/g"
Wert
Das wohlbekannte Symbol Symbol.replace
.
class CustomReplacer {
constructor(value) {
this.value = value;
}
[Symbol.replace](string) {
return string.replace(this.value, "#!@?");
}
}
console.log("football".replace(new CustomReplacer("foo"))); // "#!@?tball"
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