Andrew said:
If this is not in a BlockStatement, it should be
function Bar(obj)
{
so that a declaration takes place, not an probably undeclared definition.
// blah
}
var foo = new Bar(self);
In Bar is 'this' and 'obj' the same thing?
Of course not. The above example works only if there is an object in the
scope chain that has the `self' property (otherwise it results in a
ReferenceError). In an HTML UA environment this object is a Window object.
It's `self' property refers to that Window object itself (so that property
is in fact quite useless).
In `Bar', when it is used as a constructor due to the `new' keyword, `this'
refers to the object created(/constructed), which is a Bar object, that is,
an object that has the Object object and Bar.prototype in its prototype
chain; not a Window object, and certainly not the Window object that may be
in the scope chain.
But in `Bar', when it is instead called [on absence of the `new' keyword but
presence of the Call Operator `('...`)'], `this' could refer to the same
object as `self' does, if `Bar' is defined in global context or used in
local context but was not declared before.
PointedEars