Home >Web Front-end >JS Tutorial >javascript small example on inheritance_javascript skills
//Worker.prototype=Person.prototype;//If the prototype is a negative value, the subclass's sayJob method and the Person parent class will also have a sayJob method, because it is passed by reference
//Change to the following method, the subclass will not affect the parent class:
for(var i in Person.prototype)
{
Worker.prototype[i]=Person.prototype[i] ;
}
Worker.prototype.sayJob=function()
{
alert(this.job);
}
var p=new Person('lisi','male');
//alert(p.sayJob);
var w=new Worker('zhangsan','male','soy sauce');
w.sayName();
w.saySex();
w.sayJob() ;