这种逻辑的预期结果是 每次我调用函数rest() 该生物的健康应该恢复到10 当我尝试调用函数休息时 我得到了 未捕获的TypeError:无法读取未定义的属性“健康”
(我想将函数绑定到DOM,当单击'rest'图像时,函数rest()被调用并且 该生物的健康恢复)
const creature = {
name: 'apiGong',
alive: true,
inventory: [],
health: 5,
item: {type: "claws", damage: 1,
},
}
function rest(creature){
let health = creature.health
while (health < 10){
health++
}
return health;
}