javascript inheritance using the prototype property

by THavamani 2013-08-05 17:41:01

how to inherit the property of one class into another class in javascript

For example

function car() {}
car.prototype.bar = function(){ return 'car';}

function bus() {}
bus.prototype = new car() ; // now it will work
bus.prototype.bar = function(){ return 'bus'; }

var b = new bus ;
console.log(b.bar());


In the above example properties of class 'car' is accessed by object of class 'bus'
999
like
0
dislike
0
mail
flag

You must LOGIN to add comments