为什么要使用字符串插值?
嗨,我正在为一个开源 Javascript 库编写字符串插值。我刚刚了解字符串插值的概念,有点困惑?为什么我们要这么麻烦地进行字符串插值呢?它有什么优点?
另外,您可以向我指出有关 Javascript 中字符串插值的任何资源吗?与我分享吗?
谢谢
Possible Duplicate:
When is it better to use String.Format vs string concatenation?
Hi, I am writing String Interpolation for an open source Javascript library. I just get to know the concept of String interpolation and am a bit confused? Why do we even go into so much trouble to make String Interpolation? What are its advantages?
Also it there any resources on String interpolation in Javascript that you can point me to? Share with me?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
字符串插值也称为字符串格式化。优点是:
1. 代码清晰,
更难阅读和编辑
比Java/.Net 方式
python 方式
JavaScript 流行方式
2. 速度/内存使用
创建多个字符串然后连接它们会使用更多内存,并且比一次创建单个字符串慢。
我曾经写过一个 javascript 字符串格式化程序 -
String interpolation is also known as string formatting. Advantages are:
1. code clarity
is harder to read and edit than
Java/.Net way
python way
JavaScript popular way
2. speed/memory use
Creating multiple strings and then concatenating them uses more memory and is slower than creating a single string one time.
I once wrote a javascript string formatter-