用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
,應該就知道了