Skip to content

Instantly share code, notes, and snippets.

@mhayes mhayes/inheritance.js
Last active Sep 15, 2015

What would you like to do?
Simple javascript inheritance (as i currently understand it)
var Mammal = function (name) { = name;
Mammal.prototype.sayHello = function () {
return "Hello, I'm a " +;
var Cow = function (name) {
Mammal.apply(this, arguments);
Cow.prototype = new Mammal();
Cow.prototype.constructor = Cow;
// Usage example
var jerseyCow = new Cow("jersey cow");;
var magicCow = new Cow("magic cow");;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.