donburks
12/28/2014 - 1:03 AM

Non-Instance Safe JS

Non-Instance Safe JS

function Cat(colour, size) {
  this.colour = colour;
  this.size = size;

}

Cat.prototype.meow = function() {
  console.log("Meow");
};

function Garfield() {
}

Garfield.prototype = new Cat('orange', 'fat');

var gf = new Garfield();

gf.meow(); //Meow, as expected.

Cat.prototype.swish = function() {
  console.log("TAIL SWISH!");
};

gf.swish(); //TAIL SWISH, even though it wasn't part of the original inheritance.