Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Simple Inheritance
- # based on http://blogs.msdn.com/b/eternalcoding/archive/2014/08/20/simple-inheritance-with-javascript.aspx?utm_source=javascriptweekly&utm_medium=email
- inheritesFrom = (child,parent) ->
- child.prototype = Object.create parent.prototype
- ClassA = ->
- @.name = "class A"
- ClassA.prototype.print = ->
- console.log @.name
- a = new ClassA()
- ClassB = ->
- @.name = "class B"
- @.surname = "I am the child"
- inheritesFrom(ClassB, ClassA)
- b = new ClassB()
- ClassB.prototype.print = ->
- ClassA.prototype.print.call(@)
- console.log @.surname
- b.print()
- ClassC = ->
- @.name = "Class C"
- @.surname = "I am the grand-child"
- inheritesFrom(ClassC, ClassB)
- ClassC.prototype.print = ->
- ClassB.prototype.print.call(@)
- console.log "everything is awesome ..."
- c = new ClassC()
- c.print()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement