Last active
December 12, 2015 12:38
-
-
Save philogb/4773616 to your computer and use it in GitHub Desktop.
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 inherit(from, to) { | |
function F() {} | |
F.prototype = from.prototype; | |
to.prototype = new F(); | |
} | |
var Animal = function() { | |
}; | |
Animal.prototype.eat = function() { | |
console.log('eating'); | |
}; | |
var Person = function() { | |
}; | |
inherit(Animal, Person); | |
Person.prototype.sayHi = function() { | |
console.log('person saying hi'); | |
}; | |
var p = new Person(); | |
p.eat(); | |
p.sayHi(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment