Node.js examples for Object:Inheritance
Create Animal Object and hierarchy
function Animal(name){ this.name = name | "animal"; this.sleep = function(){ console.log(this.name+' is sleeping'); };// w w w .j a v a2s . com } Animal.prototype.eat = function(){ console.log(this.name+' is eating'); }; function Cat(){ } Cat.prototype = new Animal(); Cat.prototype.name = 'cat'; var cat = new Cat(); console.log(cat); console.log(Cat);