CoffeeScript 中的解析错误 +骨干保存功能
我正在尝试将 CoffeeScript 与 Backbone.js (通过 Brunch)结合使用,并且想在模型中实现保存功能,但它拒绝编译,我一直无法弄清楚原因。我需要将参数传递到保存函数并实现回调。
下面的代码在第二行给出了 Unexpected ':'
错误,但我不确定为什么:
class exports.Tag extends Backbone.model
defaults:
id: null
tagId: null
found: false
location: "Not yet found..."
finders: []
pointValue: 0
unlockCode: ""
verifyCode = ( code ) ->
@save { tagId: @get 'tagId', unlockCode: code },
success: ( model, response ) ->
@trigger 'verifySuccessful', response
error: ( model, response ) ->
@trigger 'verifyFailed', response
任何帮助表示赞赏...谢谢!
I'm trying to use CoffeeScript with Backbone.js (via Brunch) and I want to implement a save function in my model, but it refuses to compile and I have been unable to figure out why. I need to both pass parameters into the save function and implement callbacks.
The code below gives an Unexpected ':'
error on the second line, but I'm not sure why:
class exports.Tag extends Backbone.model
defaults:
id: null
tagId: null
found: false
location: "Not yet found..."
finders: []
pointValue: 0
unlockCode: ""
verifyCode = ( code ) ->
@save { tagId: @get 'tagId', unlockCode: code },
success: ( model, response ) ->
@trigger 'verifySuccessful', response
error: ( model, response ) ->
@trigger 'verifyFailed', response
Any help appreciated...thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
就在这里,你正在混淆解析器
是这个吗?
还是这个?
两者都可以修复错误,但它们显然意味着不同的事情。
我想补充一点,隐式括号确实很棒,但只有在最简单的情况下才能利用它。我通常使用的规则是省略一行中第一个函数调用的括号,并将它们用于所有其他函数。这条规则可以让你完全摆脱这个问题。
It's here, you are confusing the parser
Is that this?
Or this?
Either will fix the error, but they obviously mean different things.
And might I add, implicit parens are indeed awesome, but take advantage of that awesome only in the most simple of circumstances. A rule I usually use is that omit parens for the first function invocation in a line, and use them for all others. This rule would have saved you from this issue entirely.