请参阅以下来自 this GitHub file 的第 14-20 行的代码.为什么 Google 在 require 函数中使用反引号或“模板文字”,而不是常规的单引号或双引号?
该代码来自 Google 在 AppEngine 上使用 NodeJS 的教程中的测试脚本。我研究了模板文字和 require 函数,但找不到任何资源来解释为什么要在 require 语句中使用模板文字,或者它会产生什么影响。
'use strict';
const testConfig = require(`./_test-config`);
const proxyquire = require(`proxyquire`).noPreserveCache();
const sinon = require(`sinon`);
const test = require(`ava`);
const utils = require(`@google-cloud/nodejs-repo-tools`);
最佳答案
相关PR can be found here . PR 没有说明这样做的任何特定原因,这表明它要么是开发人员的品味,要么是 ES 功能的展示。
Google 确实有 an updated JS code style document如果您好奇他们喜欢 JS 的编写方式,它涵盖了较新的语法。
关于javascript - 为什么 Google 在这些 NodeJS 需要的函数中使用反引号或 "template literals"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49765199/