function?People?()?{
this.name='codeman'
};
People.prototype?=?{
showName?:?function?()?{
alert(this.name);
},
showAge?:?function?()?{
alert(this.age);
}
};
function?Student?()?{
People.call(this);
this.job='codeTeacher'
};
for?(?var?k?in?People.prototype){
Student.prototype[k]=People.prototype[k];//這里的People.prototype[k]應該是一個方法(函數),也就是引用類型
?????????????????????????????????????????//?那么當我更改Student里的showName方法的話,People里的不是也應該被改掉么,為什么沒改掉
}
//?Student.prototype=People.prototype
Student.prototype.showJob=function?()?{
alert(this.job);
}
Student.prototype.showName=function()?{
alert('superman');?????????????
}
var?peo?=?new?People();
peo.showName();?//還是‘codeman’
關于JS淺拷貝和深拷貝的問題
慕田峪8701529
2017-11-28 20:25:40