Possible Duplicate:
Is it possible to gain access to the closure of a function?
Say I have the following implementation of the revealing module pattern:
var myModule = (function() {
var myVar,
_self = this;
function setMyVar( myVar ) {
_self.myVar = myVar;
}
return {
setMyVar: setMyVar
}
})()
myModule.setMyVar('happy');
What I want to do is set the module level myVar to be 'happy'. This doesn't work because 'this' is equal to window in the anonymous parent function. One easy work around would be to avoid child-parent name collisions, but putting that aside, is there a way I could have access to a reference to the anonymous function scope from inside a nested child function?