好的,下面的函数充当构造函数来创建一个 Employee 对象(没问题)。但是当我使用此功能创建 3 名新员工时,我在某处搞砸了。
我知道我应该设置属性并打印员工的姓名和电话号码,但是我遗漏了某些东西或某些东西放错了地方。
在此先感谢您的帮助。
function Employe() {
var = name;
var = phone;
this.getName = function () {
return this.name;
}
this.setName = function (name, phone) {
this.name = name;
this.phone = phone;
};
}
var emp1 = newEmployee;
this.Name = 'jo';
this.Phone = ' 555-5551'
document.write(Employee.name Employee.phone);
var emp2 = newEmployee;
this.Name = 'jim';
this.Phone = '555-5552';
document.write(Employee.name Employee.phone);
var emp3 = newEmployee;
this.Name = 'jon';
this.Phone = '555-5553';
document.write(Employee.name Employee.phone);