Michael Winter wrote:
On 19/04/2006 21:50, Ed Jay wrote:
[Creating variables without a var statement]
This summary is misleading, see below.
I'm seeking global scope, so it appears I'm OK. Thanks.
I would still not recommend it. I certainly feel that it helps make code
clearer; globals are announced, rather than implied by an assignment
with no corresponding variable declaration. More importantly, perhaps,
explicit declarations prevent name collisions in MSIE when an element
has an id attribute value that matches a global identifier. Without the
declaration, code will cause a fatal error.
It is simply a completely different animal.
If something is assigned to an unqualified identifier that was not declared
before, scope chain resolution will create a _property_ of the Global
Object (unless, as you pointed out, there is a host object in the scope
chain before having this property, and introducing a problem), and _not_
a variable (therefore, you can apply `delete' on it, provided that the
owner is the Global Object).
If instead something is assigned to a declared identifier, scope chain
resolution will always target (a property of) the Variable Object of the
execution context the identifier was declared in (which is specified and
implemented to be a native object), and therefore a variable (that cannot
be deleted).
PointedEars