为什么在 coffeescript 函数中放置 if/else 会出现语法错误
Why do I get a syntax error for placing if/else in a coffeescript function
我在 coffeescript 函数中放置了条件逻辑,我得到了一个有用的编译错误 rails can't parse 'compile ((execjs):17:19)'
这是我的简化代码:
defaultFilterByDate = () ->
if (true) {
alert 'hello'
}
当我重新加载页面时。我的 rails 环境不喜欢这样。为什么会出现此错误?
因为 coffeescript 在没有 {}
的情况下仍然有效,正确的代码应该是:
defaultFilterByDate = () ->
if (true)
alert 'hello'
没有()
甚至在1行也可以:
defaultFilterByDate = () -> if true then alert 'hello'
我在 coffeescript 函数中放置了条件逻辑,我得到了一个有用的编译错误 rails can't parse 'compile ((execjs):17:19)'
这是我的简化代码:
defaultFilterByDate = () ->
if (true) {
alert 'hello'
}
当我重新加载页面时。我的 rails 环境不喜欢这样。为什么会出现此错误?
因为 coffeescript 在没有 {}
的情况下仍然有效,正确的代码应该是:
defaultFilterByDate = () ->
if (true)
alert 'hello'
没有()
甚至在1行也可以:
defaultFilterByDate = () -> if true then alert 'hello'