可能重复:
Javascript: Do I need to put this.var for every variable in an object?为什么我必须使用this.canvas?
我跑进用下面的代码有问题:
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
财产,但没有任何其他财产。有谁知道原因并可以提供解释?谢谢!
'但没有任何其他property'尝试'height' – Musa
是啊,我发现了这件事...对不起我的愚蠢 –