for (var i = 0; i < somearray.length; i++)
{
myclass.foo({\'arg1\':somearray[i][0]}, function()
{
console.log(somearray[i][0]);
});
}
You can pass variables values to annoymous function by using callback, something like
myclass.foo(function(variable){
return function(){
console.log(variable);
}
})(variableValue);
);
check this post: https://shahpritesh.wordpress.com/2013/09/06/javascript-function-in-loop-passing-dynamic-variable-value/