JSFiddle - React, Tailwind, and code Playground
by deepak sisodiya
JavaScript
// prototypal inheritance in javascript
var alert = function (str) {
var st = document.createTextNode(str);
var p = document.createElement('p');
p.appendChild(st);
document.querySelector('body').appendChild(p);
}
function Vehicle(hasEngine, hasWheels) {
this.hasEngine = hasEngine || false;
this.hasWheels = hasWheels || false;
this.name = function() {
return alert("deepak")
};
}
function Car (make, model, hp) {
this.base = Vehicle;
this.base(true,true)
this.hp = hp;
this.make = make;
this.model = model;
}
Car.prototype = new Vehicle();
Car.prototype.displaySpecs = function () {
alert(this.make + ", " + this.model + ", " + this.hp + ", "
+ this.hasEngine + ", " + this.hasWheels);
}
var myAudi = new Car ("Audi", "A4", 150);
myAudi.displaySpecs()
myAudi.name()
Vehicle.prototype.hasTrunk = true;
alert(myAudi.hasTrunk)