VK said:
[...]
"self" is a window property reffering to the current window.
Correct so far.
So
var self = this;
equal to
var windows.self = windows.self;
which is wrong and pointless.
This is utter nonsense.
1. The global object in most HTML UAs is the object referred to by
its `window', not `windows', property.
2. The identifier in a VariableDeclaration expression is not subject
to scope chain resolution. Instead, the variable object of the
respective execution context is added a new property if there is
not already one with that name. `var self' does not mean
`var window.self' but rather
if (!hasProperty(referenceToVariableObject, "self"))
{
referenceToVariableObject.self = undefined';
}
3. A globally declared variable with identifier `self' somewhat extends
the scope chain so that it takes precedence over the `self' property
of the global object that the `window' property *probably* refers to
on lookup, i.e. on scope chain resolution, and, since it cannot be
undeclared, making a previously defined `self' property of the global
object inaccessible until reload.[1]
(Thus I prefer `_global' as identifier for the global object reference
rather than `self').
4. The `this' reference is only equal to `window.self' iff[2] both refer
to the variable object of the common (execution) context. In a common
Web browser (which is the AOM environment required for a `window.self'
property to refer to the global object) this would apply iff the
`self' variable would be declared in global context.
You probably want to read and understand ECMAScript Edition 3,
especially chapter 10, before uttering further comments on the subject.
PointedEars
___________
[1] At least this applies to JavaScript 1.5 in Gecko-based browsers.
However, AIUI ECMAScript 3, section 10.1.3, states that globally
declared variables with identifiers ("names") of already defined
properties of the global object (which is the variable object
here) must not change the value of that property. Yet it does
in the mentioned environment. Did I miss something?
[2] if, and only if