为什么这个 Coffeescript 中需要括号?
Why parenthesis is needed in this Coffeescript?
我有这段代码
@_showSection(
{ redirect: url, token: token },
FailedView)
在 Coffeescript 中,括号是可选的,所以我尝试删除它们
@_showSection
{ redirect: url, token: token },
FailedView
我得到了一个SyntaxError: unexpected INDENT
我尝试了其他一些更改,例如
@_showSection
redirect: url, token: token
FailedView
它们也不被 coffeescript 编译器接受。
为什么在这种情况下不能接受删除括号?
这对我来说很好用:
@_showsection
redirect: url, token: token
FailedView
而且你在第二个例子中的缩进是错误的。您也可以将 key/value 对分别放在一行上。
@_showsection
redirect: url
token: token
FailedView
没有用的是将对象参数用大括号放在自己的行上。
编辑:
如果你想要一个带大括号的解决方案,你可以这样去做:
@_showsection {
redirect: url,
token: token
},
FailedView
另外,如果你想要所有额外的,你可以使用对象描述的缩写语法(如果你使用大括号):
@_showsection {
redirect: url,
token},
FailedView
我仍然找不到第一个参数在第二行用大括号开始的地方。
我有这段代码
@_showSection(
{ redirect: url, token: token },
FailedView)
在 Coffeescript 中,括号是可选的,所以我尝试删除它们
@_showSection
{ redirect: url, token: token },
FailedView
我得到了一个SyntaxError: unexpected INDENT
我尝试了其他一些更改,例如
@_showSection
redirect: url, token: token
FailedView
它们也不被 coffeescript 编译器接受。
为什么在这种情况下不能接受删除括号?
这对我来说很好用:
@_showsection
redirect: url, token: token
FailedView
而且你在第二个例子中的缩进是错误的。您也可以将 key/value 对分别放在一行上。
@_showsection
redirect: url
token: token
FailedView
没有用的是将对象参数用大括号放在自己的行上。
编辑: 如果你想要一个带大括号的解决方案,你可以这样去做:
@_showsection {
redirect: url,
token: token
},
FailedView
另外,如果你想要所有额外的,你可以使用对象描述的缩写语法(如果你使用大括号):
@_showsection {
redirect: url,
token},
FailedView
我仍然找不到第一个参数在第二行用大括号开始的地方。