在没有模板化表达式的情况下使用 ES6 模板文字语法有什么缺点吗? [英] Is there a downside to using ES6 template literals syntax without a templated expression?

查看:7
本文介绍了在没有模板化表达式的情况下使用 ES6 模板文字语法有什么缺点吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有理由(性能或其他)不对 javascript 源文件中的所有字符串使用反引号模板文字语法?如果是,那是什么?

Is there a reason (performance or other) not to use backtick template literal syntax for all strings in a javascript source file? If so, what?

我应该更喜欢这个吗:

var str1 = 'this is a string';

超过这个?

var str2 = `this is another string`;

推荐答案

不使用它们的最重要原因是并非所有环境都支持 ES6.

The most significant reason not to use them is that ES6 is not supported in all environments.

当然,这可能根本不会影响您,但仍然:YAGNI.除非您需要插值、多行文字或未转义的引号和撇号,否则不要使用模板文字.何时在 JavaScript 中使用双引号或单引号? 中的许多论点也继续存在.与往常一样,保持代码库一致,并在不需要特殊样式的情况下仅使用一种字符串文字样式.

Of course that might not affect you at all, but still: YAGNI. Don't use template literals unless you need interpolation, multiline literals, or unescaped quotes and apostrophes. Much of the arguments from When to use double or single quotes in JavaScript? carry over as well. As always, keep your code base consistent and use only one string literal style where you don't need a special one.

这篇关于在没有模板化表达式的情况下使用 ES6 模板文字语法有什么缺点吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆