function Person(name,sex){ this.name = name this.sex = sex } Person.prototype.showName=function(){ console.log(this.name) } Person.prototype.showSex=function(){ console.log(this.sex) }
function Coder(name,sex,job){ //构造函数伪装 调用父级的构造函数--继承父级属性 Person.call(this,name,sex) this.job = job } //原型链继承父级方法 for(var i in Person.prototype){ Coder.prototype[i]=Person.prototype[i] } Coder.prototype.showJob = function(){ console.log(this.job) } let a1 = new Coder('夯实','男','农民') a1.showName()