<script>
function Person(name,sex) {
this.name=name;
this.sex=sex;
}
Person.prototype.showName=function () {
alert(this.name);
};
Person.prototype.showSex=function () {
alert(this.sex);
};
function Worker(name,sex,job) {
//这是调用父级,的构造函数-----为了继承属性(学名:构造函数伪装)
//this->new 出来的worker 对象
Person.call(this,name,sex);
this.job=job;
};
//原型链 通过原型来继承父级的方法
// Worker.prototype=Person.prototype;
for(var i in Person.prototype){
Worker.prototype[i]=Person.prototype[i];
}
var oP2=new Worker("ble","男","程序员");
oP2.showName();
Worker.prototype.showJob=function () {
alert(this.job);
};
var oP2s=new Person("ble","男","程序员");
oP2s.showJob();
</script>
网友评论