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’
qq_药药_0
相关分类