function registerEmployee(p:any){
return p
}
const emp1 = registerEmployee({
name:'james',
salary:10000,
bonus:undefined as (number | undefined),
performance:4.5,
//对象方法,当然this也有嵌套函数调用的深坑
updateBonus(){
if(!this.bonus){
this.bonus = this.salary * this.performance
}
},
})
// 执行对象方法
emp1.updateBonus()
console.log(emp1)
/* 输出结果:
{
"name": "james",
"salary": 10000,
"bonus": 45000,
"performance": 4.5
}
*/ | 留言与评论(共有 0 条评论) “” |