On Thursday, 9 June 2011 22:25:34 UTC+10, Stefan Weiss wrote:
>
> On 09.06.2011 01:23, RobG wrote:
> > A function's this keyword is never "empty", it*always* references an
> > object.
>
> ... unless you're running in strict mode.
>
> (function () {
> "use strict";
> console.log(typeof this); // undefined
> })();
>
It seems GG is getting confused, I can't see some posts in the original UI,
I have to use the "new GG" to see them. As a consequence you may see
duplicate replies from me. It's enough to make me go back to Usenet and
leave GG groups altogether. Anyhow...
The joys of ES5:
*10.4.3 Entering Function Code*
The following steps are performed when control enters the execution context
for function code contained in function object *F*, a caller provided *
thisArg*, and a caller provided *argumentsList*:
1. If the function code is strict code, set the ThisBinding to *thisArg*
.
So if the caller doesn't provide a *thisArg*, it is undefined. It also means
calling a constructor without new in strict mode will throw an error if it
assigns anything to *this*.
--
Rob
--
To view archived discussions from the original JSMentors Mailman list:
http://www.mail-archive.com/[email protected]/
To search via a non-Google archive, visit here:
http://www.mail-archive.com/[email protected]/
To unsubscribe from this group, send email to
[email protected]