<script>
//员工方法
function Emp(post,wage){
this.post = post;
this.wage = wage;
}
//部门方法
function Dept(dname){
this.dname = dname;
this.emps = []; //用来封装查询出来的员工信息
}
//将员工添加到部门的方法 prototype=源文件
Dept.prototype.addEmp(emp){
this.emps.push(emp);
}
//判断职位涨工资
Dept.prototype.Raose(){
for(var i=0;i<this.emps.length;i++){
var emps = this.emps;
if(emps[i].post == "manager"){
emps[i].wage *= 1.05;
}else{
emps[i].wage *= 1.01;
}
}
return emps;
}
var emp1 = new Emp("manager",30000);
var emp2 = new Emp("teacher",15000);
var emp3 = new Emp("other",4000);
var dept = new Dept("南方IT");
//添加员工到用户
dept.addEmp(emp1);
dept.addEmp(emp2);
dept.addEmp(emp3);
//控制台输出
var empArray = dept.Raose;
console.log(empArray);
</script>
网友评论