I have a function call in my script that contain a callback function call on a fadeOut call. I’m trying to pass the paren’t function parameter into the callback function, but I can’t seem to get it working.
The general script structure is:
function aFunction(aVar){
anElement.fadeOut(200, function(){
someFunctionCall(aVar);
});
}
The call is performed correctly, but the variable is not passed. It’s probably a scoping issue on the variable but I don’t quite understand the concept here.
This code
is correct as written. Your inner function, and any other functions you declare, automatically have access to all variables in the containing scope. The function you’re passing to fadeOut will form a closure over aVar, and continue to have access to it even after aFunction has long since returned.