Created
May 9, 2016 09:27
-
-
Save Frodigo/0a9b3f3dddb35efe78288e44d1a9bf47 to your computer and use it in GitHub Desktop.
JavaScript inheritance (borrowing and setting prototype)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function() { | |
Parent.prototype.say = say; | |
Child.prototype = new Parent(); | |
function Parent (name) { | |
this.name = name || 'Paul'; | |
} | |
function say () { | |
console.log(this.name); | |
} | |
function Child (name) { | |
Parent.apply(this, arguments); | |
} | |
var parent = new Parent('John'); | |
parent.say(); | |
var kid = new Child('Alan'); | |
kid.say(); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment