VK said:
Oh my... And *this* you were reading for so many years?!
It took me only a few minutes to find this (a text search for "Global
Object" is not really that hard), whereas you most certainly would have
never found it as you obviously lack any minimum clue about the
understanding of formal language specifications. Instead you trust your
fantasies about how things really are, most certainly induced by simplified
explanations for language newbies from Microsoft or elsewhere, and you are
disproven by specification definitions _and_ implementation reality each
and every time. Still you continue to trust them. There is a word for
that; the most polite substitute is "self-delusion".
I really should sit down one day and read ECMA-262 throughout:
If you only would.
this may answer many strange comments I'm getting.
Those "strange comments" describe specified and _implemented_ reality.
Your comments merely describe your fantasies.
No, [this] doesn't refer to the Global object,
Yes, it does, in global execution context.
it refers to the Host object which is in OP's case current window object.
Will you eventually recognize that there is not "the Host object"?
(There are a number of host objects. All DOM objects are host objects,
for example.)
There is a simless tunnelling mechanics
There is no "seamless tunneling mechanics"! It is so plain and simple that
even you should be able to recognize it: `window' is a property of the
_native_ Global Object that refers to its owner. It is a host-defined
property of the Global Object, one added by the host environment when
control enters the global execution context, as are other properties (like
navigator, location etc.). Using the `window' property of the Global
Object as base object reference in a modifying property access usually _has
to_ modify the corresponding property of the Global Object in that case.
That does not make the Global Object itself _a_ host object at all.
between Global and Host objects so they mainly act as one unit.
Nonsense.
But sometimes they don't - like in OP's case:
<script type="text/javascript">
alert(undefinedVar); // error
Once again you are providing code and its outcome, but you do not say what
you expect from it instead. So one can only guess what was meant, and I
for one are not particularly inclined to do so, given your continuous
display of your misconceptions about almost(?) everything discussed here,
and therefore your ultimate failure of being able to be considered a
competent developer and a reasonable discussion partner.
But JFTR: It has already been said that the above is a scope chain issue,
specified plain mechanical logic, and I have explained it now in very much
detail in (probably, if you read it
very slowly, you will be able to understand it one day). The bottom line
is: Exactly /because/ the native Global Object is the last object in every
scope chain, and it has no such property here, the ReferenceError exception
is thrown here.
alert(this.undefinedVar) // 'undefined'
This is a property access and not an Identifier evaluation, therefore it
follows different rules. Those rules are defined in ECMAScript Edition 3
Final, subsection 11.2.1, while Identifier evaluation is defined in
subsection 10.1.4. Even you should be able to recognize the difference
between the algorithms, and therefore the difference between their possible
outcome.
BTW: ECMAScript Edition 3 is what JavaScript 1.5/6 (Gecko-based UAs),
JScript 5.5+ (IE-based UAs), Opera 6+-based UAs, and KHTML-based UAs
(Konqueror, Safari) implement. Your mere notion elsewhere that this
edition of the specification has anything to do with NN 4.5 (October
1998) is ridiculous; NN 4.5 supported JavaScript 1.3 (NN 4.06 to 4.8),
which did implement ECMAScript Edition _1_ (without supporting the
`instanceof' operator introduced in Edition 3, for example).
PointedEars