2015-08-28 60 views
0

我现在使用ESLint prefer-template强制自己使用template strings而不是字符串连接。常规字符串和模板字符串之间的性能差异?

这让我想到是否需要在模板字符串格式上使用常规字符串,例如,

console.log('Why use this? It requires me to escape different quotes depending on the context. In this case \'.'); 
console.log(`When I can use this. It allows me to use all types of quotes (e.g. ', ") without ever worrying about escaping them.`); 

我意识到JSPerf不理想的分析工具,但至少在一个静态的字符串的情况下,我无法观察到任何性能损失,例如http://jsperf.com/es-string-vs-template

+0

原来ESLint [引用](http://eslint.org/docs/rules/quotes)规则已经支持“反向”选项。 – Gajus

回答

1

你说得对,应该没有任何性能差异。

您只需确保转义`${而不是'"