javascript - 如何以正确的方式调用 rest() 函数
问题描述
这个逻辑的预期结果是,每次我调用函数 rest() 时,生物的健康应该恢复到 10 当我尝试调用函数 rest 时,我得到一个 Uncaught TypeError: Cannot read property 'health' of undefined
(我想将该函数绑定到 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;
}
解决方案
推荐阅读
- html - 使用 sas mixins 以根据边距位置附加值
- html - 我的媒体查询效果不佳,我不知道我做错了什么。它在前一段时间有效,但不再有效
- postgresql - PostgreSQL系统表损坏怎么办?
- amazon-web-services - 执行 PutItem 时出现 ValidationException:缺少项目中的键:ClientError
- java - Java Firebase Admin SDK 在代理后面连接
- java - 使用相同的 TCP 端口接受和连接
- qt - QObjectPicker 减慢应用程序的速度
- apache-spark - 未应用 Hive PartitionFilter
- ubuntu - 如何通过“notify-send”和“crontab”在 ubuntu18.04 上设置通知?
- postgresql - 本地卷 K8s 上的性能 Postgresql