I'm very new to coffeescript. So what does this error actually mean?
this is the class
class Animation
constructor: (t) ->
@startTime: t
I'm trying to set it up so that this class has a member startTime initialized to t during construction. Am I doing it wrong?
Your code is creating an object in the constructor (and not saving the reference anywhere) with a key of @startTime
. The error occurs because @
isn't a valid character for an object key.
Try this instead:
class Animation
constructor: (@startTime) ->
Here's the generated JavaScript:
var Animation;
Animation = (function() {
function Animation(startTime) {
this.startTime = startTime;
}
return Animation;
})();
Here's where you can see the syntax for what you wanted to do: http://coffeescript.org/#classes
Here's the syntax you were incorrectly and unintentionally using: http://coffeescript.org/#literals (the section titled "Objects and Arrays")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With