0
我正在使用webgl应用程序。我有starsList
阵列,由于某种原因,当我运行这个功能:TypeError:x未定义 - JS
function initTextures() {
for (i = 0; i < starsList.length; i++) {
starsList[i].texture = gl.createTexture();
starsList[i].texture.image = new Image();
starsList[i].texture.image.onload = function() {
handleLoadedTexture(starsList[i].texture)
}
starsList[i].texture.image.src = starsList[i].name + ".gif";
}
}
我得到这个错误:
TypeError: starsList[i] is undefined
handleLoadedTexture(starsList[i].texture)
虽然在循环的第一行定义starsList[i].texture
。
有什么想法为什么?