Consider the following example:
var a = 100;
function afunc(infunc){
a = 10;
var f = function (){
console.log(a);
};
f.call();
infunc.call();
}
afunc(function (){ console.log(a); });
We assign a value of 10 to a within the scope of afunc, and then call two functions one after the other that simply log the value of a. In this case, you would expect both functions to log 10 as the value of a, and that's in fact what happens.
In your example, infunc will be executed in essentially the same scope as any local function defined in afunc, regardless of where it was actually defined. Since you assigned a value to a in a narrower scope, that's the value of a when you call infunc.
Functions do retain some scope from their definition, as in the following example:
function bfunc(){
var b = 'hello';
return function (){ console.log(b); };
}
afunc(bfunc());
Here, the anonymous function returned by bfunc is actually called from within the scope of afunc, but it's still able to log the correct value of b as it was assigned in the original scope. If you were to change afunc to assign a different value to b, it would still log "hello" because the b defined in afunc is a different variable than the b defined in bfunc.