JSFiddle - React, Tailwind, and code Playground
JavaScript
var ClassA = function() {
//this function is totally empty
};
ClassA.prototype = {
jump: function() {},
dance: function() {
if (this.canDance) {
console.log("dance");
}
else {
console.log("Jerry Seinfeld ate too much cake");
}
}
};
ClassA.implementOn = function(targetClassOrObject) {
for ( var prop in ClassA.prototype ) {
targetClassOrObject[ prop ] = ClassA.prototype[ prop ];
}
};
var ClassB = function() {
this.canDance = true;
ClassA.call(this); // <------------What's the purpose of this line?
};
ClassA.implementOn(ClassB.prototype);
var instanceOfB = new ClassB();
instanceOfB.dance();
(new ClassA()).dance();