obG wrote:
On Nov 22, 4:37 pm, getsanjay.sha.. .@gmail.com wrote:
>You don't need 'var' keyword to *declare* variables
Yes, you do. A variable without var isn't declared, it is created as
a property of the global object when the code executes. It is
equivalent (more or less) to:
window[variableName] = 'foo';
(Sigh. [psf 10.1] More or less; rather less. It should be
window['variableName'] = 'foo';
if that; `window' does not need to refer to the Global Object.)
IOW, a variable that is not declared with `var' is not a variable at all.
The identifier will refer to a property of an object O in the Scope Chain.
O is often the Global Object, which should be at the end of the Scope Chain,
but O does not need to. During identifier resolution, the first object that
reports to have such a property will be O.
In fact, O may be not a host object which makes this initialization-only
approach error-prone. It is known that in the MSHTML DOM IDs and names of
markup elements make up property names of an host object that is before the
Global Object in the Scope Chain which is why you get a runtime error if you
try write access to those properties.)
(Maybe I should create a template for that as people keep forgetting it even
though I post the reminder frequently.)
PointedEars