|
@mathias | |||||
|
Replacing all occurrences of a substring with another string is a common operation.
Unfortunately, doing this correctly is surprisingly hard in JavaScript. 🤯
The new String.prototype.replaceAll API is here to help! 🎉
v8.dev/features/strin… pic.twitter.com/zzwqmXQD91
|
||||||
|
||||||
|
Lucas Engel
@lucasengel
|
11. stu |
|
What exactly is the issue with using the regexp?
|
||
|
|
||
|
Mathias Bynens
@mathias
|
11. stu |
|
It’s explained in the write-up. (Spoiler: you have to remember to escape special RegExp chars + to use the g flag.)
|
||
|
|
||
|
Amandeep Kochhar
@amandeepkochhar
|
11. stu |
|
Yay!! All these v8 features are supported using babel or directly using latest chrome version?
|
||
|
|
||
|
Mathias Bynens
@mathias
|
11. stu |
|
See v8.dev/features/strin… — for now, you’ll have to use Babel/polyfills. But the functionality is coming to browsers soon! Both @SpiderMonkeyJS and @v8js already have flagged implementations.
|
||
|
|
||
|
Sebastião Tolentino
@tolentek
|
12. stu |
|
But this only work on browser! The replace method with regex works in node too.
|
||
|
|
||
|
Mathias Bynens
@mathias
|
12. stu |
|
What makes you say that? Once a version of @v8js supporting replaceAll rolls into Node.js, it will work there as well, like any other language feature.
|
||
|
|
||
|
Dayton Lowell
@daytonlowell
|
11. stu |
|
Oh hey, you created the WebKit bug report. Anyway, it’s not linked in that article. ¯\_(ツ)_/¯
|
||
|
|
||
|
Mathias Bynens
@mathias
|
11. stu |
|
Feel free to submit a PR that adds the link! I didn’t because there has been no real activity on the bug yet.
|
||
|
|
||
|
Noah Rodenbeek
@DrawnByMouse
|
11. stu |
|
"constant"
|
||
|
|
||
|
Mathias Bynens
@mathias
|
12. stu |
|
What are you referring to?
|
||
|
|
||