ES6 / ECMA6模板文字 - 無效我想嘗試使用模板文字并且它不起作用:它顯示文字變量名稱而不是值。我使用的是Chrome v50.0.2(和jQuery)。例:console.log('categoryName: ${this.categoryName}\ncategoryElements: ${this.categoryElements} ');輸出:${this.categoryName} categoryElements: ${this.categoryElements}
3 回答

楊魅力
TA貢獻1811條經驗 獲得超6個贊
JavaScript 模板文字需要反引號,而不是直引號。
您需要使用反引號(也稱為“嚴重重音” - 您將在1鍵旁邊找到) - 而不是單引號 - 來創建模板文字。
反引號在許多編程語言中很常見,但對JavaScript開發人員來說可能是新手。
示例:
categoryName="name";categoryElements="element";console.log(`categoryName: ${this.categoryName}\ncategoryElements: ${categoryElements} `)
輸出:
VM626:1 categoryName: name categoryElements: element
添加回答
舉報
0/150
提交
取消