<script>
window.onload=function(){
function Person(name,age){
this.name=name;
this.age=age;
}
Person.prototype.getName=function(){
return this.name;
}
Person.prototype.getAge=function(){
return this.age;
}
function Teacher(name,age,subject){
Person.call(this,name,age);
this.subject=subject;
}
Teacher.prototype=Object.create(Person.prototype);
Teacher.prototype.constructor=Teacher;
Teacher.prototype.getSubject=function(){
return this.subject;
}
Teacher.prototype.getInfo=function(){
return "new"+this.getName();
}
var t=new Teacher("louis",30,"javascript");
console.log(t.getInfo());
var p=new Person("tina",25);
console.log(p.getName());
console.log(t instanceof Teacher);
console.log(t instanceof Person);
};
</script>
网站声明:如果转载,请联系本站管理员。否则一切后果自行承担。