用typescript编译出来的代码,如下:
function test(template, name, age) {
console.log(template);
console.log(name);
console.log(age);
}
let myname: string = "Keyon";
let myage: number = 18;
test`Hello, my name is ${myname}, I'm ${myage}.`;
function test(template, name, age) {
console.log(template);
console.log(name);
console.log(age);
}
var myname = "Keyon";
var myage = 18;
(_a = ["Hello, my name is ", ", I'm ", "."], _a.raw = ["Hello, my name is ", ", I'm ", "."], test(_a, myname, myage));
var _a;
(_a = ["Hello, my name is ", ", I'm ", "."], _a.raw = ["Hello, my name is ", ", I'm ", "."], test(_a, myname, myage));这里直接一个小括号,里边的像参数一样的,是什么意思?还有那个 _a.raw 是什么?
括起来执行多个表达式
你可以在第一段代码的
test
函数内打印下template.raw
,应该就知道了