You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
letx="Hi",y="Kevin";varres=messagefn`${x}, I am ${y}`;console.log(res);functionmessagefn(literals,value1,value2){console.log(literals);// [ "", ", I am ", "" ]console.log(value1);// Hiconsole.log(value2);// Kevin}
ES6 系列之模板字符串
如果你碰巧要在字符串中使用反撇号,你可以使用反斜杠转义:
值得一提的是,在模板字符串中,空格、缩进、换行都会被保留。
模板字符串支持嵌入变量,只需要将变量名写在
${}
之中,其实不止变量,任意的 JavaScript 表达式都是可以的。值得一提的是,模板字符串支持嵌套:模板标签是一个非常重要的能力,模板字符串可以紧跟在一个函数名后面,该函数将被调用来处理这个模板字符串,举个例子:
原文链接:ES6 系列之模板字符串
The text was updated successfully, but these errors were encountered: