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]應(yīng)該是一個(gè)方法(函數(shù)),也就是引用類型
?????????????????????????????????????????//?那么當(dāng)我更改Student里的showName方法的話,People里的不是也應(yīng)該被改掉么,為什么沒改掉
}
//?Student.prototype=People.prototype
Student.prototype.showJob=function?()?{
alert(this.job);
}
Student.prototype.showName=function()?{
alert('superman');?????????????
}
var?peo?=?new?People();
peo.showName();?//還是‘codeman’
關(guān)于JS淺拷貝和深拷貝的問題
慕田峪8701529
2017-11-28 20:25:40