我遇到了以下代码的问题:
var BuildMiniMap = function(camera, mapSize, width){
this.camera = camera;
this.canvas = document.getElementById('gameCanvas');
this.mapSize = mapSize;
this.width = width;
this.height = Math.floor(mapSize[1]/(mapSize[0]/width));
alert(canvas);
}
var miniMap = new BuildMiniMap(camera, [800, 600], 200);
在网页中运行会导致控制台报错:
Uncaught ReferenceError: canvas is not defined
我必须this.canvas
改用。这仅发生在canvas
财产上,而不会发生在任何其他财产上。有谁知道原因并能给出解释吗?谢谢!