我的JavaScript:

todo.completed = !todo.completed;


错误:

Uncaught TypeError: Cannot read property 'completed' of undefined
    at Object.toggleCompleted (script.js:34)
    at Object.toggleCompleted (script.js:89)
    at HTMLButtonElement.onclick ((index):33)
toggleCompleted @ script.js:34
toggleCompleted @ script.js:89
onclick @ (index):33


我在这里想念什么吗?

最佳答案

似乎您尚未声明变量todo。尝试类似todo = {};的问题,如果您有任何问题,请告诉我!

关于javascript - 未捕获的TypeError:无法读取未定义的属性foo,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/41234576/

10-09 16:43