Skip to content

Instantly share code, notes, and snippets.

@Frodigo
Created May 9, 2016 09:27
Show Gist options
  • Save Frodigo/0a9b3f3dddb35efe78288e44d1a9bf47 to your computer and use it in GitHub Desktop.
Save Frodigo/0a9b3f3dddb35efe78288e44d1a9bf47 to your computer and use it in GitHub Desktop.
JavaScript inheritance (borrowing and setting prototype)
(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