Javascript inheritance example

// Create a class
var vehicle = function(modelname){
var that = {};
that.engine = “suzuki”;
that.tyres = “MRF”;
that.modelname = modelname;
that.getModel = function(){
console.log(this.modelname+”has engine”+that.engine);
return that;

var twowheeler = function(model){
var that = vehicle(model);
that.type = “two wheeler”;
return that;

var glamour = twowheeler(“g20”);
glamour.engine; // should display suzuki
glamour.getModel(); // display g20 has suzuki

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s