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

Unexpected . #222

Closed
ted-strauss-K1 opened this issue Aug 8, 2013 · 5 comments
Closed

Unexpected . #222

ted-strauss-K1 opened this issue Aug 8, 2013 · 5 comments
Labels

Comments

@ted-strauss-K1
Copy link

Compiling JS -> Coffee

App.IndexController = Ember.ObjectController.extend({
    friends: function() {
        return this.get('model').get('friends');
    }.property()
})

Compiles to:

App.IndexController = Ember.ObjectController.extend(friends: ->
  @get("model").get "friends"
.property())

And that coffee script yields an error: unexpected . by the compiler.

@timaschew
Copy link
Member

this is a strange syntax, you sure, that this is valid js ? I mean the property() after the inner function

@paul-english
Copy link

Ember extends javascript to allow functions to be represented as values in their templates and in other areas. The use of property is a declarative way of saying this function represents a dynamic value of the object being defined. It's valid js.

@ted-strauss-K1
Copy link
Author

is it valid js or valid ember-js?
by extending javascript, did they make it incompatible with coffeescript, or just this translator app?
how could the above code be rewritten as coffeescript?

@paul-english
Copy link

It's valid js, ember probably uses prototypical inheritance to add property() onto any function object.

You can fix the error in coffeescript by surrounding the anonymous function in parens. This lets the coffeescript compiler know that you're calling a function off the anon function, rather than something else.

App.IndexController = Ember.ObjectController.extend(friends: (->
  @get("model").get "friends"
).property())

@michaelficarra
Copy link
Contributor

See #155. Duplicate of #135.

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

No branches or pull requests

4 participants