prototype inheritance

by bhupendra negi

JavaScript

// test for proto

function Car(name)
{
    this.brand = name;
    this.service = function() { alert("Serivce err !");}
}

function Bike(name)
{
    this.make=name;
    this.stop = function() { alert("stoooopss") ;};
    this.service = function() { alert("Bike service !");}
}


// adding function to proto so that fn does not get repeated in each instance of objects

Bike.prototype = new Car("SUZUKI");

var bike1 = new Bike("GS 150R");
console.log(bike1);

alert (bike1.make);
alert (bike1.brand);
bike1.service();