Arguments to JavaScript Anonymous Function

前端 未结 5 893
悲&欢浪女
悲&欢浪女 2021-02-13 11:47
for (var i = 0; i < somearray.length; i++)
{
    myclass.foo({\'arg1\':somearray[i][0]}, function()
    {
        console.log(somearray[i][0]);
    });
}
5条回答
  •  一个人的身影
    2021-02-13 12:07

    All the functions/methods can be used as callbacks only. When you call the callback function you pass variables to it.

    var myclass = {
      foo: function(params, callback){
        // do some stuff
        callback(variable1, variable1, variableN);
      }
    }
    

提交回复
热议问题