disabling "use strict"; everywhere

Andreas Rossberg rossberg at google.com
Wed Jan 30 09:18:34 PST 2013

On 30 January 2013 18:00, Andrea Giammarchi <andrea.giammarchi at gmail.com> wrote:
> let me rephrase ...
> putting `with(this){` before any build process/inlined library and `}` at
> the end of all concatenated files **nothing** is strict anymore ^_^
> function isStrict() {"use strict";
>   return this;
> }
> isStrict(); // undefined
> now, wraping the whole thing inside a with statement
> with(this){
>   function isStrict() {"use strict";
>     return this;
>   }
>   alert(isStrict()); // global object
> }
> forget the Function hack, there is no library able to ensure itself to be
> executed in strict mode.
> Using the width statement around any code makes it not strict.

That is, er, balls, of course. All that happens here is that inside
the 'with', a call to a _toplevel_ function like 'isStrict()' becomes
'this.isStrict()', and so receives the global object. That does not
otherwise change strictness, however. Try:

  with(this) {
    function isStrict() { "use strict"; var x; delete x; }

for example. Moreover, calls to functions not resolving to global
definitions are completely unaffected, so are calls using 'call' or

  with(this) {
    function isStrict() { "use strict"; return this; };
    function call(f) { f() };
    alert(call(isStrict)); // undefined
    alert(isStrict.call()); // undefined

Both calls would return window in sloppy mode.


More information about the es-discuss mailing list