我已经检查了同样问题的其他问题,但是它们对我来说不起作用.
我收到错误:Cannot set property '0' of undefined用我的JavaScript; 我正在使用Google Chrome.
var thisInstance = new Grid(100,100);
thisInstance.initGrid();
function Grid(maxX, maxY) {
this.grid = new Array();
this.gridMaxX = maxX;
this.gridMaxY = maxY;
this.initGrid = function() {
for(var i = 0; i < this.gridMaxX; i++) {
this.grid[i] = new Array();
}
}
}
Run Code Online (Sandbox Code Playgroud)
我打电话时收到错误:
thisInstance[1][0] = 1;
请询问您是否需要更多信息!
由于您尝试访问[0]未定义的对象,因此会触发该错误.
更换
thisInstance[1][0] = 1;
Run Code Online (Sandbox Code Playgroud)
通过
thisInstance.grid[1][0] = 1;
Run Code Online (Sandbox Code Playgroud)
thisInstance只是一个实例Grid,而不是一个数组.
| 归档时间: |
|
| 查看次数: |
6612 次 |
| 最近记录: |