JSFiddle - React, Tailwind, and code Playground
by dhchow
JavaScript
function establishInheritance(childClass, parentClass) {
childClass.prototype = new parentClass();
childClass.prototype.constructor = childClass;
};
function Animal() {
var test = "yo";
var init = function() {
}
init();
};
Animal.prototype.eat = function() {
return 'Yum';
};
function Dog() {};
establishInheritance(Dog, Animal);
Dog.prototype.bark = function() {
return 'Arf';
};
Dog.prototype.eat = function(){
return "Yuck";
}
function Collie() {};
establishInheritance(Collie, Dog);
var lassie = new Collie();
console.log(lassie instanceof Collie);
console.log(lassie instanceof Dog);
console.log(lassie instanceof Animal);
// inherits up to upmost class
console.log(lassie.eat());
console.log(Collie.prototype, lassie.__proto__);
console.log(Dog.prototype, Collie.prototype.__proto__);
console.log(Animal.prototype, Dog.prototype.__proto__);