CoffeeScript Class Definitions
The CoffeeScript homepage gives the following example to demonstrate CoffeeScript’s class syntax:
Anyone experienced with class-based inheritance should have little trouble understanding this code.
The constructor functions are then generated as follows:
Notice how easily the Snake constructor can access its Animal prototype using the __super__ property.
The functional style does nothing with prototypes. Inheritance is implemented by creating an object from a base function, similar to a constructor, but without the need for the new operator. Access to super methods is accomplished by extending the built-in Object and Function objects. Notice that any child object wanting access to a super method must create a new function pointing to the super method.
Finally, if you want a much more thorough comparison and richer examples of prototypal vs. functional inheritance styles, this article provides both and makes a very strong case for the use of prototypal inheritance.
This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License.