Baseline Widely available
Symbol.replace
ì ì ë°ì´í° ìì±ì ì ìë ¤ì§ ì¬ë³¼ì¸ Symbol.replace
를 ëíë
ëë¤. String.prototype.replace()
ë° String.prototype.replaceAll()
ë©ìëë íì¬ ê°ì²´ì ì¼ì¹íë 문ìì´ ì¼ë¶ë¥¼ ëì²´íë 첫 ë²ì§¸ ì¸ììì ì´ ì¬ë³¼ì ì°¾ìµëë¤.
ìì¸í ë´ì©ì 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