template-literals

Backticks calling a function

巧了我就是萌 提交于 2019-11-25 23:32:51
问题 I\'m not sure how to explain this, but when I run console.log`1` In google chrome, I get output like console.log`1` VM12380:2 [\"1\", raw: Array[1]] Why is the backtick calling the log function, and why is it making a index of raw: Array[1] ? Question brought up in the JS room by Catgocat, but no answers made sense besides something about templating strings that didn\'t really fit why this is happening. 回答1: It is called Tagged Template in ES-6 more could be read about them Here, funny I