You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As far as I can tell CoffeeScript supports only single inheritance (as for example Java). Multiple inheritance on the other hand can be painful, but it would be very nice if it supported traits (like in Scala - maybe not that powerfull, but kind of).
To be clear traits are like java interfaces, but unlike them - they provide implementation and attributes inside. However, like the Java interfaces, we cannot have actual instance of a trait. Also they are (in practice) quite like Python's mixins. For example:
class Vehicle
constructor: (@power) ->
getPower: ->
@power
trait TurboBoost
getPower: ->
2 * super()
class Ferrari extends Vehicle with TurboBoost
getPower: ->
super() + 3
ferrari = new Ferrari 18
ferrari.getPower()
###
this would give: 2 * (3 + 18) = 42
###
There could be simple implementation of them as simple JS objects (like 'modules' in Prototype toolkit, which are mixed into classes at creation time).
The text was updated successfully, but these errors were encountered:
The reason why we don't have language support for mixins in CoffeeScript is because they're not supported by JavaScript -- you can't actually have more than one prototype chain on an object, meaning that the mixin's properties are simply copied over, which breaks both inheritance, and subsequent changes to the mixin. If you'd like to mix things in yourself, I recommend an extends function.
As far as I can tell CoffeeScript supports only single inheritance (as for example Java). Multiple inheritance on the other hand can be painful, but it would be very nice if it supported traits (like in Scala - maybe not that powerfull, but kind of).
To be clear traits are like java interfaces, but unlike them - they provide implementation and attributes inside. However, like the Java interfaces, we cannot have actual instance of a trait. Also they are (in practice) quite like Python's mixins. For example:
There could be simple implementation of them as simple JS objects (like 'modules' in Prototype toolkit, which are mixed into classes at creation time).
The text was updated successfully, but these errors were encountered: