首页 > nodejs `${}` 取值用法

nodejs `${}` 取值用法

刚刚接触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的值的。


这个其实是ES6中的模版字符串语法。https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals

【热门文章】
【热门文章】