making |this| an error (was Re: for own(...) loop)

Quildreen Motta quildreen at
Wed Nov 9 07:50:14 PST 2011

2011/11/9 John J Barton <johnjbarton at>

> I'm sure this has been discussed before, but isn't is possible and
> desirable to make |this| illegal in "using strict;" when it can be
> determined from the AST alone that |this| will bind to |window|?  eg:
>   Object.keys(foo).forEach(function(key) {
>     // this is undefined-> window
>   });
> This case kind of case is because, as others have noted, incorrect
> |this| binding most often occurs in two cases: 1) mixed OO and
> functional programming (as above) and 2) callback defn.
In `strict-mode', |this| would resolve to `undefined' inside that function
anyways. I'm not a fan of making constructs "illegal" just because
their semantics might be confusing, even more so when such
disallowance would vary highly in context. It would be bound to
make things more confusing, imho.

Block lambdas are the best solution I can see right now.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list