Create Animal Object and hierarchy - Node.js Object

Node.js examples for Object:Inheritance

Description

Create Animal Object and hierarchy

Demo Code


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);

Related Tutorials