Cat class - Node.js Object

Node.js examples for Object:Class Definition

Description

Cat class

Demo Code


function Cat(name, owner) {
  this.name = name;//from   ww  w . j av a2s.com
  this.owner = owner;
}

Cat.prototype.cuteStatement = function() {
  return `${this.owner} loves ${this.name}`;
};

Cat.prototype.cuteStatement = function() {
  return `Everyone loves ${this.name}!`;
};

Cat.prototype.meow = function() {
  return "meow!";
};

let victor = new Cat('victor', 'tu');
victor.meow = function() {
  return "mew!";
};


let tu = new Cat('tu', 'victor');
console.log(tu.meow());
console.log(victor.meow());

Related Tutorials