TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

ECMAScript proposal: String.prototype.replaceAll

56 点作者 joeyespo超过 5 年前

10 条评论

bendiksolheim超过 5 年前
I don’t understand the rationale behind throwing an exception if you provide a regular expression which lacks the g modifier. This seems really counter intuitive. I would expect replaceAll to replace all occurrences no matter if the regular expression is global or not.
评论 #21853528 未加载
评论 #21855357 未加载
评论 #21854011 未加载
评论 #21853435 未加载
评论 #21853468 未加载
评论 #21856103 未加载
zzo38computer超过 5 年前
I would have make the "escapeForRegExp" function built-in (it seems to me the kind of thing should be built-in), perhaps called RegExp.quote. (I would also to add support for many features of PCRE.)
评论 #21853999 未加载
评论 #21853570 未加载
rienbdj超过 5 年前
I wish the pipeline operator were standardised so we can stop fiddling with prototypes.
robbrown451超过 5 年前
This would be nice, using RegEx&#x27;s for such simple cases is ugly, especially if the replace string is dynamic (so can&#x27;t be done with a literal).<p>I find myself using a combination of split and join a lot to avoid that.
评论 #21853467 未加载
kapv89超过 5 年前
I think JS has had enough of syntactic sugar like features. What it needs as a next step in its natural evolution is support for proper multi-threading with atomics, mutex etc.
评论 #21857301 未加载
biolurker1超过 5 年前
So much fuss for a small function
评论 #21854020 未加载
yepthatsreality超过 5 年前
Mmmmm...syntactic sugar...
评论 #21853494 未加载
评论 #21853718 未加载
评论 #21853437 未加载
pier25超过 5 年前
While this is a nice little addition to the language, personally I&#x27;d prefer to see more substantial changes like decorators, observables, class properties, optional static types, etc.
评论 #21855443 未加载
2ion超过 5 年前
Exhibit $n why ECMAScript is not a well-designed language at its core. It ought to be as simple as the Lua core language but it isn&#x27;t (the object type was a good start but then stopped being one). Boltons after boltons. For things as simple as this.
评论 #21853544 未加载
评论 #21853627 未加载
tomaszs超过 5 年前
Couldnt we just have an object called String2 with a replace method that replaces all occurances without any regex at all? Like in any other language? We could fix entire Javascript just by adding two to all object names.
评论 #21856636 未加载
评论 #21856717 未加载