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
。
有什麼想法爲什麼?