var f = function(arg) {
if (arg != null) {
document.write(arg);
document.write("<br/>");
} else if (arg == undefined) {
document.write("undefined<br/>");
}
else {
document.write("<br/>");
}
};
//inheritance
//base class
function Vehicle(vType){
this.vType = vType;
Vehicle.prototype.displayType = function(){f(this.vType);};
};
//instance class
function Car(color,brand){
this.color = color;
this.brand = brand;
};
//setting baseclass to protoype property
Car.prototype = new Vehicle("Four wheeler");
var v = new Vehicle("None");
v.displayType();
var c = new Car("black","lotus");
c.displayType();f(c instanceof Vehicle);f(c instanceof Car);
//abstract class
//its kinda abstract because we cant instantiate it via new VehicleAbs()
var VehicleAbs = {
vType: "None",
displayType: function(){f(this.vType);}
};
//instance class
function Bike(color, brand){
this.color = color;
this.brand = brand;
this.vType = "Two Wheeler";
};
//setting baseclass to prototype property
Bike.prototype = VehicleAbs;
var b = new Bike("black", "Ducati");
b.displayType();
//f(b instanceof VehicleAbs); this will throw error
f(b instanceof Bike);
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.