I want to use local variables like ‘thisModule’ in scope of the given ‘functionToRun’ without passing them as parameters.
Onsetsu.run = function (functionToRun) {
var thisModule = Onsetsu.namespace(resolvedModule.moduleName);
functionToRun();
};
Onsetsu.run(function() {
/* thisModule should be visible here */
});
Unfortunately ‘thisModule’ is not defined in the scope.
Is there a convinient way to bring ‘thisModule’ into the functions scope?
Define a variable in the closest shared scope of
functionToRunandOnsetsu.run. Assign the variable withinOnsetsu.run:Assuming your actual code is more complicated than that:
If
Onsetsuis a library that you can’t (or don’t want to) modify, then you are out of luck.Edit: You could also assign a property on the function itself:
You can access the property from within
functionToRunviaarguments.callee:Or by giving the function a name: