steveosoule
6/16/2015 - 4:28 PM

JavaScript Object Prototype Inheritance

JavaScript Object Prototype Inheritance

// FROM: http://tobyho.com/2010/11/22/javascript-constructors-and/

function Mammal(){
}
Mammal.prototype.breathe = function(){
    // do some breathing
    return "breathing...";
}
function Cat(){
}
Cat.prototype = new Mammal()
Cat.prototype.constructor = Cat
// now cat too can breathe!