如何将值作为传递值传递给javascript回调/clousure
我正在尝试将整数值I传递给回调,但回调无法正常工作,因为I可用作参考如何将值作为传递值传递给javascript回调/clousure,javascript,callback,closures,Javascript,Callback,Closures,我正在尝试将整数值I传递给回调,但回调无法正常工作,因为I可用作参考 for (var i = this.texturesPath.length - 1; i >= 0; i--) { var textureIndex = i; loader.load(baseTexturePath + this.texturesPath[i], function(texture) { scope.textures[textureIndex] = texture; }); 此场景的解决方
for (var i = this.texturesPath.length - 1; i >= 0; i--) {
var textureIndex = i;
loader.load(baseTexturePath + this.texturesPath[i], function(texture) {
scope.textures[textureIndex] = texture;
});
此场景的解决方案/方法是什么 这就是你需要的生活,所以你可以“拯救”我
@用户3804449为什么你否决了我的答案,我相信这是一个正确的答案
for (var i = this.texturesPath.length - 1; i >= 0; i--) {
(function (index){
loader.load(baseTexturePath + this.texturesPath[index], function(texture){
scope.textures[index] = texture;
})
})(i)
}