Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/464.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将值作为传递值传递给javascript回调/clousure_Javascript_Callback_Closures - Fatal编程技术网

如何将值作为传递值传递给javascript回调/clousure

如何将值作为传递值传递给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; }); 此场景的解决方

我正在尝试将整数值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;
});

此场景的解决方案/方法是什么

这就是你需要的生活,所以你可以“拯救”我


@用户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)
}