刚刚接触nodejs 今天看了一段代码 ${}
这个取值操作不是很懂,求解答
a.js如下
module.exports = {
publicPath:'abc'
}
b.js如下:
var a = require('./a');
function buildConfig() {
var b = {
publicPath: `${a.publicPath}`
}
console.log(b);
}
module.exports = buildConfig();
当我执行node b.js的时候发现是可以打印输出a.js里面定义的publicPath的值的。
This is actually the template string syntax in ES6. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals
The template character
${} can replace many string operations that were difficult to write in the past, such as:
Line break
Use ${} instead of writing:
Expression embedding
${} written as:
There are more usages, please refer to the link to adopt the answer