I have a question about variable scope in NodeJS. Lets assume that we have a function (MainFunc) that calls another function (SecondFunc). The second function has a callback:
function MainFunc(arg1, arg2, arg3)
{
SecondFunc(arg1, (respondJSON)
{
//AM I ALLOWED TO DO THE FOLLOWING?
respondJSON.name = arg2;
respondJSON.age = arg3;
}
}
As you can see my sample code, arg2
and arg3
are used inside the callback body. Am I allowed to do this? Because the MainFunc might be called several time a second by many users, Are arg2
and arg3
GUARANTEED to be the same as the arguments or might be has another value that is call by another user, just before the callback is called?