ember-script
ember-script copied to clipboard
Static properties don't work
class Test
@test = 1
causes a compiler error
Syntax error on line 2, column 2: unexpected '@' (\u0040)
1 : class Test
2 : @test = 1
Dynamix, you'll have to correct me if I'm wrong, but it looks like you should use the following syntax:
class Test
test: 1
testing = new Test()
console.log(testing.test) # => 1
When declaring a class, we pass an object as a parameter (which can be hard to tell, with (coffee/ember)script's minimal syntax.
The above is equivalent to:
class Test ( { test: 1} )
Which sets the test
property on the Test
class, which you can then access with @test
:
class Test
test: 1
testAccess: ->
console.log( @test )
testing = new Test()
testing.testAccess() # => 1
Thanks for the response. However this is not the same as a static member in coffeescript (good explanation here : http://www.cs8.my/2012/09/coffeescript-classes-and-their-variables/). Seems like this is missing in coffeescript-redux.
Oh yep, I hadn't seen that @var = "stuff"
syntax before. Doing it with a colon also breaks. Bummer