2015-08-28 96 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

你說得對,應該沒有任何性能差異。

您只需確保轉義`${而不是'"