"use strict"; prepended blindly to scripts in the wild

Andrea Giammarchi andrea.giammarchi at gmail.com
Sun Sep 19 04:03:19 PDT 2010


Hi everybody,
    sorry I could not find a way to inject myself in the original thread.

Dmitry has very valid points there and I have not seen a concrete solution
to this problem so here I am with a couple of proposals.

#1 First Script Rule
I do believe, since there is no "use quirks" directive, that once we put a
"use strict" in the global scope and in the very first script, we would like
to be sure the whole thingy uses strict.
In few words, if I am the author of the application/webpage/whatever I
should be the one responsible for strictness.
Moreover, if strict is messed up with non strict we may have horrible side
effects so ... "all strict" when global strict is set sounds reasonable
while if we do not want "all strict" we should use our own closure and most
of the libraries out there do already.

#2 Strict Label
JS labels have been there since ages so I wonder if something like this
would make sense:

// optionally with a var statement
// for all variables used in this
// strict context
strict:for(;;){

    var i = 123;
    // etc etc ...

break strict}


// optionally made semantic
// via const and a while
// const could be a var as well
const valid = true;
strict:while(valid){

    var j = 123;

break strict}


// but we don't need const or var
strict:if(true){

    // your stuff here

break strict}


Labels would be compatible and the concatenation of scripts won't be a
problem, we always have a proper block when we wont to do stuff in a strict
way where "strict" should be the reserved label name for "use strict"
activation.

What do you think?

Best Regards,
    Andrea Giammarchi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20100919/72516c43/attachment.html>


More information about the es-discuss mailing list