The this context variable
has not anything to do with Scope, in terms of how ECMAscript implements Lexical scoping underneath.
this
will always reference the object of invocation, which can change during run-time, whereas the scope / context cannot get changed. You got two function invocations there, each of those has its own Execution Context and its own Activation Object respectively Lexical Environment Record, which are used by the implementation to store any local data like formal paramteres, variables and function declarations.
What you are actually trying to achieve here, is to create a hash / namespace object which serves as container to hold data. Therefore, you shouldn't assign this
, but just create your own Object.
var myScope = { }; // respectively Object.create( null );
In strict mode, the implementation will just set this
to undefined
for any function which got invocated as is. That means, the value of this
is decided of how a function gets called. In your case, its a self-executing function and hence, its this
will always be undefined
in strict mode and window
(global) in non strict mode.