Baseline Widely available
Symbol.replace
ã¯éçãã¼ã¿ããããã£ã§ãã¦ã§ã«ãã¦ã³ã·ã³ãã«ã§ãã Symbol.replace
ã表ãã¾ããString.prototype.replace()
ããã³ String.prototype.replaceAll()
ã¡ã½ããã¯ç¬¬ 1 弿°ã§ãç¾å¨ã®ãªãã¸ã§ã¯ãã«ä¸è´ããé¨åæååãç½®ãæããã¡ã½ãããããã®ã·ã³ãã«ã§æ¢ãã¾ãã
詳ããã¯ãRegExp.prototype[Symbol.replace]()
ãString.prototype.replace()
ã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"
å¤
ã¦ã§ã«ãã¦ã³ã·ã³ãã« 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"
仿§æ¸ ãã©ã¦ã¶ã¼ã®äºææ§ é¢é£æ
å ±
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