如下 求解释 js prototype

function employee(name,job,born)

{

this.name=name;

this.job=job;

this.born=born;

this.salary=12;

}

let c=123;

var bill=new employee('xx','ss','pp');

employee.prototype.salary=function(){

    return this.born;

}

alert((bill.salary+'--000---'+employee.prototype.salary()));


var alise=new employee('xx','ss','pp');

alert((alise.salary+'--000---'+alise.salary()));


鸿蒙传说
浏览 416回答 1
1回答

DIEA

第一个是12--000---undefined,employee.prototype.salary(),this.born没赋值,return undefined;第二个alise.salary()出错,alise.salary是this.salary,为12,employee中有this.salary=12,把employee.prototype.salary覆盖,找的是this.salary(),报错
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript