The a
variable is just that, a variable. It's visible in the scope of innerMethod
(which is just a nested function), as a
, which is how it was declared (ie. JavaScript has lexical scoping rules, inner functions can see variables of the functions they're defined inside of).
this
isn't the same as the local scope of the MyObject
constructor.
You've seen that self
is an alias for this
of MyObject
, and that innerMethod
has overwritten this
in its own scope. Still, since this
is not an alias for function scope, neither self.a
nor this.a
will ever work here.
For a more rigorous explanation of lexical scoping you can e.g. start at wikipedia: http://en.wikipedia.org/wiki/Scope_(computer_science)
You can read about the execution contexts and identifier resolution rules in the ECMA standard http://es5.github.com/#x10.3