-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Enhancements to the class keyword #279
Comments
There was a discussion about this in an earlier ticket relating to executable class bodies. It was discounted, but perhaps a similar possibility to support both would be to use the class Animal constructor: (name) -> @name: name Animal.all.push @ @greet: -> alert "hello $@name" all: [] count: -> all.length |
I think prototypical methods are more common. Less typing for the common case would be nice, although @ reads quite well. |
weepy: that would be perfect I think, although I agree with runeb; better to favour the common case. |
Also, in ruby-style class body, |
it does make sense - in ruby, but JS is a bit different. it would be confusing to swap the position of the @'s ala ruby style. |
Well, since the construct (and the keywords used) suggest we are acting on a class, rather than on a prototype, a keyword like Also, since we'd used them a lot less often than when defining methods for instances, I think |
Perhaps it would be better to use the class Animal constructor: (name) -> @name: name Animal.all.push @ ::greet: -> alert "hello $@name" all: [] count: -> all.length |
|
Yes - it does - so meaning here is |
ahh yeah, right, ignore my last comment. Anyway, that's really close to the way it was before the class keyword was introduced. Also, due to the js own prototype-based paradigm, we tend to not refer to base classes (read fictive base class) directly so often. So I don't know if those rare case warrants such a change from the current statu quo. |
This is very close to my original suggestion in the executable class bodies ticket, my suggestion was to add
I still think it's kinda neat. Especially since there's a zen-like no-magic thing to this, everything is just a closure. But the |
Alright, we now have class (static) properties as part of the class definition, if you want them, on master. Just use the
It works the same way for properties as well. The compiler is now using it, but it's only needed in a small handful of places in the codebase. Closing the ticket. |
I’ve been experimenting a little bit lately with using CoffeeScript’s classes, but I have unfortunately one behaviour which is a bit limiting
The class keyword allows you to define the constructor and functions to be attached to the prototype, but it doesn’t offer any way to attach functions to the object itself.
For example if I wanted to implement something like a class method I currently have to directly define it as a property on the object:
It would be nice if CoffeeScript could provide some shortcut to doing this, rather than having to repeatedly type Foo.
The text was updated successfully, but these errors were encountered: