Skip to content

Instantly share code, notes, and snippets.

@akkerman
Last active December 20, 2015 22:09
Show Gist options
  • Save akkerman/6202454 to your computer and use it in GitHub Desktop.
Save akkerman/6202454 to your computer and use it in GitHub Desktop.
Object.prototype.mixin = (aClass) ->
for key, value of aClass
@[key] = value
for key, value of aClass.prototype
@::[key] = value
@
class Voertuig
constructor: (@naam, @snelheid=0)->
getNaam: => @naam
getSnelheid: => @snelheid
setSnelheid: (@snelheid) =>
class Auto extends Voertuig
constructor: (naam, snelheid=0) ->
super(naam, snelheid)
rij: => console.log(@naam + " rijdt")
class Boot extends Voertuig
constructor: (naam, snelheid=0) ->
super(naam, snelheid)
vaar: => console.log(@naam + " vaart")
class Amfibie extends Voertuig
@mixin Boot
@mixin Auto
constructor: (naam, snelheid=0) ->
super(naam, snelheid)
a = new Amfibie("Hovercraft", 120)
console.log(a.getNaam())
a.rij()
a.vaar()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment