On Tue, Jan 19, 2016 at 9:54 AM, Kevin Gibbons <[email protected]>
wrote:

> I'm not sure if this is well-known; it was certainly surprising to me.
>
> Consider the following program:
> `let func = () => 0;
>
> (function(){
>   {
>     function func() {
>       return 1;
>     }
>   }
>   return func();
> })();`
>
> The return value of the second function depends on whether this program is
> evaluated in strict mode or not. In strict mode (for example, as a Module),
> annex B.3.3 does not apply, so it returns 0. In sloppy mode (for example,
> as a Script), annex B.3.3 applies and it returns 1.
>
> You can see how the semantics change on the scope analysis demo we've just
> put up at
> shift-ast.org/scope.html?code=let%20func%20%3D%20()%20%3D%3E%200%3B%0A%0A(function()%7B%0A%20%20%7B%0A%20%20%20%20function%20func()%20%7B%0A%20%20%20%20%20%20return%201%3B%0A%20%20%20%20%7D%0A%20%20%7D%0A%20%20return%20func()%3B%0A%7D)()%3B#demo
> : as a Module the last `func` identifier refers to the outer `func`, and as
> a Script it refers to the inner one.
>
> Is it considered acceptable to have such large changes in strict vs
> non-strict semantics for unremarkable code?
>

That is the right question. The answer is yes. Sloppy mode exists only to
avoid breaking crappy legacy code, rather than to have any coherent
semantics. All new code should be strict, especially if you want it to work
or to have anyone understand it.




> If not, should B.3.3 be made to apply in strict mode?
>

ABSOLUTELY NOT!

(Or rather since the answer to your first question is yes, and you started
this one with "If not", the answer to this one is Mu ;).)



> _______________________________________________
> es-discuss mailing list
> [email protected]
> https://mail.mozilla.org/listinfo/es-discuss
>
>


-- 
    Cheers,
    --MarkM
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to