3 ms·
> leaky and half-featured classes. This is a common willful misconception. CoffeeScript classes are isomorphic to JavaScript prototypes -- the do precisely the
by jashkenas 15y ago
> leaky and half-featured classes.
This is a common willful misconception. CoffeeScript classes are isomorphic to JavaScript prototypes -- the do precisely the same thing. In addition, there is a shorthand syntax for prototyping objects, if that's more your style:
Dog = ->
...
Dog::bark = ->
...
Dog::run = ->
...
Note that the above will produce the same result as:
class Dog
bark: ->
...
run: ->
...
- tcard 15y agoI didn't mean that CoffeeScript classes don't cover prototypes —but the other way around: prototypes can't implement the whole typical class abstraction (encapsulation, etc.). So I think CoffeeScript would do better implementing a completely new syntactic abstraction over prototyping that fix all the JavaScript awkward ambiguities than adapting classes to prototypes. But it's still OK, I like and use CS classes.
- gryzzly 15y agothere are performance reasons for that choice, the prototypal inheritance + constructors are way faster than anything else at the moment