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!
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.