ES2015 Babel字符串插值无法使用撇号(但使用双引号)

时间:2015-06-23 10:46:29

标签: javascript ecmascript-6 string-interpolation babeljs

我正在使用babel / grunt来学习一些ES2015。

根据this post,单引号和双引号之间的Javascript没有真正的区别。即“测试”和“测试”。

当尝试字符串插值时,似乎babeljs存在问题(或者更可能是 - 我)。请问以下代码有什么问题?

根据this document,似乎两者都应该有用。 Chrome控制台中没有错误。

工作Js:

var name = "Bob", time = "today";
alert(`Hello ${name}, how are you ${time}?`);

透明至:

var name = "Bob",
    time = "today";
alert("Hello " + name + ", how are you " + time + "?");

提供预期结果。

失败的Js:

var forename = 'bob', surname = 'test';
alert('hello ${forename} ${surname} - how are you?');

透明至:

var forename = "bob",
    surname = "test";
alert("hello ${forename} ${surname} - how are you?");

并提供以下输出:

enter image description here

1 个答案:

答案 0 :(得分:38)

你是对的, output$mygraph <- renderDygraph({ VAR<-data_xts()[,c('Var1','Var2')] dygraph(VAR) %>% dySeries(colnames(VAR)[2], axis = 'y2') %>% dyAxis("x",axisLabelFormatter=JS(getsecs), valueFormatter=JS(getsecs)) %>% dyAxis("y", label = colnames(VAR)[1]) %>% dyAxis("y2", label = colnames(VAR)[2], independentTicks = TRUE) %>% dyOptions(drawGrid = input$showgrid) %>% dyOptions(drawPoints = TRUE, pointSize = 2) %>% dyHighlight(highlightCircleSize = 3, highlightSeriesOpts = list(strokeWidth = 3)) %>% dyLegend(width = 800) %>% dyRangeSelector() d.getDate is not a function 字符串方面没有区别,但是为了进行字符串插值,你必须在模板字符串周围使用反引号,例如:

<强> ES2015

'

产生的ES5

"

Babel REPL