TypeError: 'undefined' is not an object (evaluating 'calls[name].push') with Coffeescript 1.7
knoopx opened this issue · comments
https://github.com/spine/spine/blob/dev/src/spine.coffee#L9
Operator precedence changed in Coffeescript 1.7 and calls
is evaluated to false
instead of {}
calls = @hasOwnProperty('_callbacks') and @_callbacks or= {}
is now compiled to:
calls = this.hasOwnProperty('_callbacks') && (this._callbacks || (this._callbacks = {}));
instead of:
calls = this.hasOwnProperty('_callbacks') && this._callbacks || (this._callbacks = {});
so, just this
calls = @hasOwnProperty('_callbacks') and (@_callbacks or= {})
should fix?
No, that's actually the new coffee script behaviour, you want this:
calls = (@hasOwnProperty('_callbacks') and @_callbacks) or @_callbacks= {}
i see, thanks. will try to get that patched in dev soon. think there is a couple other issues with coffeescript 1.7 that also need addressed.
What's wrong with this?
calls = @_callbacks || {}
I was also going to suggest making the code more readable instead of fixing the surface level syntax problems, but wasn't sure if the hasOwnProperty()
was necessary in there. What about:
@_callbacks = {} unless @hasOwnProperty('_callbacks') and @_callbacks
calls = @_callbacks
And we could even do away with the intermediate calls
and just use @_callbacks
in the function...
fixed in dev