我个人认为这个功能并不是那么简单。
可能有更多实用的功能我只是没有发现。
如果只是那么简单这个功能有点...
let user_type = 'ordinary';
function handle(strings, type) { // 这里指的注意的是第一个参数是个数组,将所有的字符串常量被变量分割的收集起来,第二个参数是一个变量,可以有多个变量对应的有多个参数
let output = strings[0];
let varstr;
if (type == 'ordinary') {
varstr = '单价是100元人民币';
}else {
varstr = '批发价是50元人民币';
}
return `${output}${varstr}`
}
let show = handle`您购买的商品${user_type}`
console.log(show)