Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Static properties don't work #46

Open
dynamix opened this issue Jul 16, 2014 · 3 comments
Open

Static properties don't work #46

dynamix opened this issue Jul 16, 2014 · 3 comments

Comments

@dynamix
Copy link

dynamix commented Jul 16, 2014

class Test
  @test = 1

causes a compiler error

Syntax error on line 2, column 2: unexpected '@' (\u0040)
1 : class Test
2 :   @test = 1
@clov3r
Copy link

clov3r commented May 5, 2015

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

@dynamix
Copy link
Author

dynamix commented May 5, 2015

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.

@clov3r
Copy link

clov3r commented May 5, 2015

Oh yep, I hadn't seen that @var = "stuff" syntax before. Doing it with a colon also breaks. Bummer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants