问题描述
用typescript编译出来的代码,如下:
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}.`;编译后的javascript:
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 是什么?
问题解答
回答1:括起来执行多个表达式
回答2:你可以在第一段代码的test函数内打印下template.raw,应该就知道了