Loading ...
Sorry, an error occurred while loading the content.

option.strict

Expand Messages
  • Douglas Crockford
    Some famous websites are failing on the latest browsers because they have been concatenating strict mode scripts with non-strict mode scripts. This causes the
    Message 1 of 9 , Dec 13, 2010
    • 0 Attachment
      Some famous websites are failing on the latest browsers because they have been concatenating strict mode scripts with non-strict mode scripts. This causes the non-strict scripts to fail.

      There are two ways to specify strict mode. The first is to place "use strict"; at the top of the file. This contributes to the comcatenation failure. The second is to place "use strict"; at the top of a file. This gives the strictness function scope, which is much more reliable.

      JSLint's option.strict now accepts the second form. Soon it will reject the first form.
    • AJ ONeal
      I haven t used a browser in which use strict does anything yet, but is this assumption correct? // begin myfile.js: use strict ; (function () { // this
      Message 2 of 9 , Dec 13, 2010
      • 0 Attachment
        I haven't used a browser in which "use strict" does anything yet,
        but is this assumption correct?

        // begin myfile.js:
        "use strict";
        (function () {
        // this function is in strict mode
        var nullthing = this;
        }());
        (function () {
        // this function is not in strict mode
        var globalObj = this;
        }());
        // end myfile.js



        or should I do something like this?

        (function () {
        "use strict";
        (function () {
        }());
        }());

        AJ ONeal


        On Mon, Dec 13, 2010 at 3:53 PM, Douglas Crockford <douglas@...>wrote:

        >
        >
        > Some famous websites are failing on the latest browsers because they have
        > been concatenating strict mode scripts with non-strict mode scripts. This
        > causes the non-strict scripts to fail.
        >
        > There are two ways to specify strict mode. The first is to place "use
        > strict"; at the top of the file. This contributes to the comcatenation
        > failure. The second is to place "use strict"; at the top of a file. This
        > gives the strictness function scope, which is much more reliable.
        >
        > JSLint's option.strict now accepts the second form. Soon it will reject the
        > first form.
        >
        >
        >


        [Non-text portions of this message have been removed]
      • Ger Hobbelt
        On Mon, Dec 13, 2010 at 11:53 PM, Douglas Crockford ... I assume you meant to say function in that second line? (Otherwise the only diff I see is a vs.
        Message 3 of 9 , Dec 13, 2010
        • 0 Attachment
          On Mon, Dec 13, 2010 at 11:53 PM, Douglas Crockford
          <douglas@...>wrote:

          > The first is to place "use strict"; at the top of the file.



          > The second is to place "use strict"; at the top of a file.


          I assume you meant to say 'function' in that second line? (Otherwise the
          only diff I see is 'a' vs. 'the'). A bit of googling led me to

          http://ejohn.org/blog/ecmascript-5-strict-mode-json-and-more/

          hence the assumption.

          --
          Met vriendelijke groeten / Best regards,

          Ger Hobbelt

          --------------------------------------------------
          web: http://www.hobbelt.com/
          http://www.hebbut.net/
          mail: ger@...
          mobile: +31-6-11 120 978
          --------------------------------------------------


          [Non-text portions of this message have been removed]
        • Ger Hobbelt
          ... or should I do something like this? ... Pending an answer from Mr. Crockford, I d say the latter is the preferred one. -- Met vriendelijke groeten / Best
          Message 4 of 9 , Dec 13, 2010
          • 0 Attachment
            On Tue, Dec 14, 2010 at 12:07 AM, AJ ONeal <coolaj86@...> wrote:

            > I haven't used a browser in which "use strict" does anything yet,
            > but is this assumption correct?
            >
            > // begin myfile.js:
            > "use strict";
            > [...]


            or should I do something like this?
            >
            > (function () {
            > "use strict";
            > (function () {
            > }());
            > }());
            >

            Pending an answer from Mr. Crockford, I'd say the latter is the preferred
            one.


            --
            Met vriendelijke groeten / Best regards,

            Ger Hobbelt

            --------------------------------------------------
            web: http://www.hobbelt.com/
            http://www.hebbut.net/
            mail: ger@...
            mobile: +31-6-11 120 978
            --------------------------------------------------


            [Non-text portions of this message have been removed]
          • Douglas Crockford
            ... Wrong. All functions in this file are strict. Also, if you concatenate any programs to the end of this file, they will be strict, too. ... This is better.
            Message 5 of 9 , Dec 13, 2010
            • 0 Attachment
              --- In jslint_com@yahoogroups.com, AJ ONeal <coolaj86@...> wrote:
              >
              > Iis this assumption correct?
              >
              > // begin myfile.js:
              > "use strict";
              > (function () {
              > // this function is in strict mode
              > var nullthing = this;
              > }());
              > (function () {
              > // this function is not in strict mode

              Wrong. All functions in this file are strict. Also, if you concatenate any programs to the end of this file, they will be strict, too.

              > var globalObj = this;
              > }());
              > // end myfile.js
              >
              >
              >
              > or should I do something like this?
              >
              > (function () {
              > "use strict";
              > (function () {
              > }());
              > }());

              This is better. Both functions are strict.
            • Rob Richardson
              You ve specified at the top of the file twice. Did you intend to identify the second as the top of a function ? Rob ... From: jslint_com@yahoogroups.com
              Message 6 of 9 , Dec 13, 2010
              • 0 Attachment
                You've specified "at the top of the file" twice. Did you intend to identify
                the second as "the top of a function"?

                Rob


                -----Original Message-----
                From: jslint_com@yahoogroups.com [mailto:jslint_com@yahoogroups.com] On
                Behalf Of Douglas Crockford
                Sent: Monday, December 13, 2010 3:54 PM
                To: jslint_com@yahoogroups.com
                Subject: [jslint] option.strict

                Some famous websites are failing on the latest browsers because they have
                been concatenating strict mode scripts with non-strict mode scripts. This
                causes the non-strict scripts to fail.

                There are two ways to specify strict mode. The first is to place "use
                strict"; at the top of the file. This contributes to the comcatenation
                failure. The second is to place "use strict"; at the top of a file. This
                gives the strictness function scope, which is much more reliable.

                JSLint's option.strict now accepts the second form. Soon it will reject the
                first form.
              • Douglas Crockford
                ... Yes.
                Message 7 of 9 , Dec 13, 2010
                • 0 Attachment
                  --- In jslint_com@yahoogroups.com, "Rob Richardson" <erobrich@...> wrote:
                  >
                  > You've specified "at the top of the file" twice. Did you intend to identify
                  > the second as "the top of a function"?

                  Yes.
                • AJ ONeal
                  FYI, at the top of means inside , not on top . That s why I was originally confused. // Non-strict code... (function(){ use strict ; // Define your
                  Message 8 of 9 , Dec 13, 2010
                  • 0 Attachment
                    FYI, "at the top of" means "inside", not "on top".
                    That's why I was originally confused.

                    // Non-strict code...

                    (function(){
                    "use strict";

                    // Define your library strictly...
                    })();

                    // Non-strict code...


                    http://stackoverflow.com/questions/1335851/what-does-use-strict-do-in-javascript-and-what-is-the-reasoning-behind-it


                    I believe this would be a useless statement (though I'm not sure).
                    In any case it's probably best to avoid it.


                    (function(){

                    // do stuff
                    }());

                    "use strict";

                    (function(){

                    // do stuff
                    })();


                    AJ ONeal


                    On Mon, Dec 13, 2010 at 4:26 PM, Douglas Crockford <douglas@...>wrote:

                    >
                    >
                    > --- In jslint_com@yahoogroups.com <jslint_com%40yahoogroups.com>, "Rob
                    > Richardson" <erobrich@...> wrote:
                    > >
                    > > You've specified "at the top of the file" twice. Did you intend to
                    > identify
                    > > the second as "the top of a function"?
                    >
                    > Yes.
                    >
                    >
                    >


                    [Non-text portions of this message have been removed]
                  • Jakob Kruse
                    In your second example, use strict ; is neither at the top of a file or at the top of a function, thus it has no effect. /Jakob _____ From: AJ ONeal
                    Message 9 of 9 , Dec 14, 2010
                    • 0 Attachment
                      In your second example, "use strict"; is neither at the top of a file or at the top of a function, thus it has no effect.


                      /Jakob

                      _____

                      From: AJ ONeal [mailto:coolaj86@...]
                      To: jslint_com@yahoogroups.com
                      Sent: Tue, 14 Dec 2010 00:36:05 +0100
                      Subject: Re: [jslint] option.strict

                      FYI, "at the top of" means "inside", not "on top".
                      That's why I was originally confused.

                      // Non-strict code...

                      (function(){
                      "use strict";

                      // Define your library strictly...
                      })();

                      // Non-strict code...


                      http://stackoverflow.com/questions/1335851/what-does-use-strict-do-in-javascript-and-what-is-the-reasoning-behind-it


                      I believe this would be a useless statement (though I'm not sure).
                      In any case it's probably best to avoid it.


                      (function(){

                      // do stuff
                      }());

                      "use strict";

                      (function(){

                      // do stuff
                      })();


                      AJ ONeal


                      On Mon, Dec 13, 2010 at 4:26 PM, Douglas Crockford <douglas@...>wrote:

                      >
                      >
                      > --- In jslint_com@yahoogroups.com <jslint_com%40yahoogroups.com>, "Rob
                      > Richardson" <erobrich@...> wrote:
                      > >
                      > > You've specified "at the top of the file" twice. Did you intend to
                      > identify
                      > > the second as "the top of a function"?
                      >
                      > Yes.
                      >
                      >
                      >


                      [Non-text portions of this message have been removed]



                      ------------------------------------

                      Yahoo! Groups Links





                      [Non-text portions of this message have been removed]
                    Your message has been successfully submitted and would be delivered to recipients shortly.