JavaScript - Prototypical Inheritance
by secretgspot
JavaScript
function Animal(food) {
this.food = food;
};
Animal.prototype.feed = function() {
console.log('Fed the animal ' + this.food);
};
var animal = new Animal('Strawberries');
animal.feed();
var test = animal instanceof Animal;
console.log(test);
function Cow(color){
this.color = color;
};
Cow.prototype = new Animal('Hay');
var c = new Cow('White');
c.feed();
var test2 = c instanceof Animal;
console.log(test2);