JS inheritance
by bhupendra negi
JavaScript
// create Base class
function Child(name,age)
{
this.name = name;
this.age = age;
}
Child.prototype.greet = function() {
console.log("HI this is " + this.name);
}
var c1 = new Child("Shyam",10);
//c1.greet();
function College(name,age,collegeName)
{
Child.call(this,name,age);
this.collegeName = collegeName;
}
College.prototype = Object.create(Child.prototype);
//College.prototype.constructor = College;
var col1 = new College("Ram",25,"gbpec");
//col1.greet();
console.log(col1.greet() instanceof Child);