On Sep 8, 1:04 pm, Thomas 'PointedEars' Lahn wrote:
I can't figure out another case in which a call to f()
would preset 'this' to something !== window ?
Could you show me how, when ?
(Not using 'with', .call() nor .apply())
<snip>
Disregarding quibbling about whether - window - is equivalent to the
ECMAScript global object (and there is plenty of room for quibbling in
that direction), the specification allows another situation in which a
non-property accessor to the left of call operators may allow a - this
- that was not the global object. Host functions/object methods are
explicitly allowed to return a Reference type if they want to. In the
even that a host function did return a Reference type that had a non-
activation object as its - base - and its property name referred to a
function reference value, and the call operators were directly applied
to the value returned from the call then in that second function call
the - this - keyword would refer the - base - of the Reference type
(assuming it was no an Activation object).
I am not aware of a single host method/function that behaves in this
way, but that does not mean that they do not exist, and the
specification allows for the possibility of their existence.
The form of this construct (if it exists) would be:-
HostObject.methodName()();
- where the first set of parenthesise call the method and the second
set call the return value from the first function call, which is
allowed to be a Reference type for host functions/methods.
IE host objects support this form of usage. If, for example, you had a
number of forms each with a field named 'f' IE will happily execute:-
document.forms(0)('f');
- and the call to the return value from the - docuemnt.forms(0) -
knows which of the forms it is associated with, such that the
subsequent ('f') returns the reference to the field in the correct
form. This could be achieved by - docuemnt.forms(0) - returning a
Reference type, but in practice it is not (other manipulations of the
construct can be used to demonstrate that returning a Reference type
is not what is happening here).