javascript - NodeJS 中的嵌套模板字符串错误

标签 javascript node.js

为什么以下行会导致 Node.js 中出现运行时错误?

var a = ````;

抛出:

TypeError: "" is not a function


使用 Node.js 版本 4.x、6.x、8.x 和 9.x 进行测试

最佳答案

前两个反引号是空字符串,而接下来的两个将充当 tagged template literals它将调用它之前的函数。由于 ""(empty string) 不是可调用函数,它会引发错误。

Backticks calling a function

要在模板文字中嵌套反引号,通过在它前面加上正斜杠来转义它

console.log(`\`\``);

关于javascript - NodeJS 中的嵌套模板字符串错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47903470/

相关文章:

javascript - Node Express 4 在多次 API 调用后发送响应

javascript - Node.js 脚本默默失败?

读取同一对象中的属性时出现 JavaScript 错误?

node.js - Dockerize meteor 应用程序

node.js - sails.js 水线 : maxLength not set in DB

node.js - 如何在 aws amplify for node.js 中更改用户作为管理员的电子邮件或密码

javascript - node.js(javascript)中的系统范围互斥锁

javascript - 是否可以在文档加载事件中获取鼠标光标的位置/位置

javascript - 从 PHP 更新 DIV 标签

javascript - 可能的 React 反模式 : Setting initial state from props