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

[jslint] Re: global use strict

Expand Messages
  • 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 1 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.