gpt4 book ai didi

javascript - 未捕获的类型错误 : Cannot read property 'getContext' of undefined

转载 作者:行者123 更新时间:2023-11-27 23:18:09 24 4
gpt4 key购买 nike

运行脚本时出现此错误“未捕获类型错误:无法读取未定义的属性“getContext””。似乎变量“canvas”未定义,但我不明白为什么。

var world = {
canvas: document.getElementById("myCanvas"),
context: this.canvas.getContext("2d"),
centerX: this.canvas.width / 2,
centerY: this.canvas.height / 2,
drawShape: function (shape) {
if (typeof shape.draw() === "function")
shape.draw();
}
};

最佳答案

我在 world 文字之外声明了变量 canvas 并且它正在工作

关于javascript - 未捕获的类型错误 : Cannot read property 'getContext' of undefined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35638685/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com