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

global use strict

Expand Messages
  • Woomla
    I really would have use strict ; at the top of my files instead of in every function. Off course, concatinating files on the fly, and merging third party
    Message 1 of 6 , Jan 25, 2011
    • 0 Attachment
      I really would have "use strict"; at the top of my files instead of in every function.

      Off course, concatinating files on the fly, and merging third party javascript, is a little harder, but I don't suffer from that. I have many functions that needs the statement inserted and, because I can use the statement at the file level, I prefer not to do it per function to keep my code clean and speed up development.

      Maybe I missed it, but is there more information about why it should be at function level? Or maybe there's an option for it?
    • Douglas Crockford
      ... I would have too, but given the terrible performance characteristics of browsers with respect to script loading, file level strictness is not safe. If you
      Message 2 of 6 , Jan 25, 2011
      • 0 Attachment
        --- In jslint_com@yahoogroups.com, "Woomla" <woomla@...> wrote:
        > I really would have "use strict"; at the top of my files instead of in every function.
        >
        > Off course, concatinating files on the fly, and merging third party javascript, is a little harder, but I don't suffer from that. I have many functions that needs the statement inserted and, because I can use the statement at the file level, I prefer not to do it per function to keep my code clean and speed up development.


        I would have too, but given the terrible performance characteristics of browsers with respect to script loading, file level strictness is not safe.

        If you are not suffering now, you would be suffering later.
      • Zhami
        ... What is it about browser script loading that makes file level strictness not safe: Is it that the use strict at a file level applies on a global level
        Message 3 of 6 , Jan 25, 2011
        • 0 Attachment
          --- In jslint_com@yahoogroups.com, "Douglas Crockford" <douglas@...> wrote:
          >
          > --- In jslint_com@yahoogroups.com, "Woomla" <woomla@> wrote:
          > > I really would have "use strict"; at the top of my files instead of in every function.
          > >
          > > Off course, concatinating files on the fly, and merging third party javascript, is a little harder, but I don't suffer from that. I have many functions that needs the statement inserted and, because I can use the statement at the file level, I prefer not to do it per function to keep my code clean and speed up development.
          >
          >
          > I would have too, but given the terrible performance characteristics of browsers with respect to script loading, file level strictness is not safe.
          >
          > If you are not suffering now, you would be suffering later.
          >

          What is it about browser script loading that makes file level strictness not safe: Is it that the "use strict" at a file level applies on a global level and not just to the loaded file? What about cases where all the code loaded is strict-compliant? Would it then not be safe? Or does "use strict" at a file level reach beyond loaded scripts and somehow apply to the operation of the compiler/interpreter itself (which may not be strict-compliant)?
        • Morgaut Alexandre Louis Marc
          I found the function level bieng less a problem as I often start my code creating a function scope this way, I juest had to change my code from use strict ;
          Message 4 of 6 , Jan 25, 2011
          • 0 Attachment
            I found the function level bieng less a problem as I often start my code creating a function scope

            this way, I juest had to change my code from


            "use strict";

            (function Scope_Myapp() {

            // my app code

            }());



            to

            (function Scope_Myapp() {

            "use strict";

            // my app code

            }());


            And all my functions inherit from the strictness of my scope function

            This should prevent the file loading problem...



            On Jan 25, 2011, at 1:39 PM, Zhami wrote:

            >
            >
            > --- In jslint_com@yahoogroups.com, "Douglas Crockford" <douglas@...> wrote:
            > >
            > > --- In jslint_com@yahoogroups.com, "Woomla" <woomla@> wrote:
            > > > I really would have "use strict"; at the top of my files instead of in every function.
            > > >
            > > > Off course, concatinating files on the fly, and merging third party javascript, is a little harder, but I don't suffer from that. I have many functions that needs the statement inserted and, because I can use the statement at the file level, I prefer not to do it per function to keep my code clean and speed up development.
            > >
            > >
            > > I would have too, but given the terrible performance characteristics of browsers with respect to script loading, file level strictness is not safe.
            > >
            > > If you are not suffering now, you would be suffering later.
            > >
            >
            > What is it about browser script loading that makes file level strictness not safe: Is it that the "use strict" at a file level applies on a global level and not just to the loaded file? What about cases where all the code loaded is strict-compliant? Would it then not be safe? Or does "use strict" at a file level reach beyond loaded scripts and somehow apply to the operation of the compiler/interpreter itself (which may not be strict-compliant)?
            >
            >



            [Non-text portions of this message have been removed]
          • Woomla
            As I use mootools I have code like: var MyClass = new Class( { Implements: [Options], initialize: function (options) { this.setOptions(options) },
            Message 5 of 6 , Jan 26, 2011
            • 0 Attachment
              As I use mootools I have code like:

              var MyClass = new Class(
              {
              Implements: [Options],

              initialize: function (options)
              {
              this.setOptions(options)
              },

              myfunction001: function ()
              {
              },

              //a lot more functions

              myfunction999: function ()
              {
              }
              };

              I cannot put this in a function scope because then other files cannot access it. So I guess the only way to do is to insert "use strict" in all those functions.


              > This should prevent the file loading problem...

              Where can I find more information about this "file loading problem".




              --- In jslint_com@yahoogroups.com, Morgaut Alexandre Louis Marc <morgaut@...> wrote:
              >
              >
              > I found the function level bieng less a problem as I often start my code creating a function scope
              >
              > this way, I juest had to change my code from
              >
              >
              > "use strict";
              >
              > (function Scope_Myapp() {
              >
              > // my app code
              >
              > }());
              >
              >
              >
              > to
              >
              > (function Scope_Myapp() {
              >
              > "use strict";
              >
              > // my app code
              >
              > }());
              >
              >
              > And all my functions inherit from the strictness of my scope function
              >
              > This should prevent the file loading problem...
              >
              >
              >
              > On Jan 25, 2011, at 1:39 PM, Zhami wrote:
              >
              > >
              > >
              > > --- In jslint_com@yahoogroups.com, "Douglas Crockford" <douglas@> wrote:
              > > >
              > > > --- In jslint_com@yahoogroups.com, "Woomla" <woomla@> wrote:
              > > > > I really would have "use strict"; at the top of my files instead of in every function.
              > > > >
              > > > > Off course, concatinating files on the fly, and merging third party javascript, is a little harder, but I don't suffer from that. I have many functions that needs the statement inserted and, because I can use the statement at the file level, I prefer not to do it per function to keep my code clean and speed up development.
              > > >
              > > >
              > > > I would have too, but given the terrible performance characteristics of browsers with respect to script loading, file level strictness is not safe.
              > > >
              > > > If you are not suffering now, you would be suffering later.
              > > >
              > >
              > > What is it about browser script loading that makes file level strictness not safe: Is it that the "use strict" at a file level applies on a global level and not just to the loaded file? What about cases where all the code loaded is strict-compliant? Would it then not be safe? Or does "use strict" at a file level reach beyond loaded scripts and somehow apply to the operation of the compiler/interpreter itself (which may not be strict-compliant)?
              > >
              > >
              >
              >
              >
              > [Non-text portions of this message have been removed]
              >
            • Alexandre Morgaut
              I will use uppercase notation in my examples for global variables There s at least two ways to handle it - You can use the application/framework scope to
              Message 6 of 6 , Jan 26, 2011
              • 0 Attachment
                I will use uppercase notation in my examples for global variables

                There's at least two ways to handle it

                - You can use the application/framework scope to return a value

                It is perfect for to create one single shared global object (which is a good
                practice)
                Then use the pattern Jakob just shown:

                var MY_CLASS = function applicationScope() {
                    "use strict";

                    return new Class(
                    {
                        // constructor & some properties & methods
                    };
                }();


                - You can declare your global variables globaly, and assign their value in the
                application/framework scope

                var MY_CLASS_1, MY_CLASS_2;

                (function applicationScope() {
                    "use strict";

                    MY_CLASS_1= new Class(
                    {
                        // constructor & some properties & methods
                    };

                    MY_CLASS_2= new Class(
                    {
                        // constructor & some properties & methods
                    };

                }());

                But you should consider using a single global variable as a namespace:
                (coming back to the Jakob example...)

                var MYAPP = function applicationScope() {
                    "use strict";

                    MYAPP.MyClass1 = new Class(
                    {
                        // constructor & some properties & methods
                    };

                    MYAPP.MyClass2 = new Class(
                    {
                        // constructor & some properties & methods
                    };
                }();
              Your message has been successfully submitted and would be delivered to recipients shortly.