JSFiddle - React, Tailwind, and code Playground
JavaScript
// INHERITANCE USING JS
// SUPER CLASS CONSTRUCTOR
function bank () {
this.cash = 1000;
}
// SUB CLASS CONSTRUCTOR
function thief () {
// CALL BANK CONSTRUCTOR
bank.call(this);
}
// ADD A METHOD TO BANK.PROTOTYPE
bank.prototype.steal = function () {
console.log('a thief stole '+this.cash+' dollars!');
}
// THIEF EXTENDS BANK AND INHERITS STEAL METHOD.
//thief.prototype = bank.prototype;
// thief.prototype.__proto__ = bank.prototype // also works!
thief.prototype.__proto__.__proto__ = bank.prototype; // why does this break?
let t = new thief();
t.steal(); // OUTPUT 1000.