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

Re: [jslint] Global variables

Expand Messages
  • Michael Lorton
    Woot! I think. The inconvenience of declaring globals in every file might drive developers to use proper namespaces. Or it might just suck.
    Message 1 of 3 , May 28, 2009
    • 0 Attachment
      Woot!

      I think.

      The inconvenience of declaring globals in every file might drive developers to use proper namespaces. Or it might just suck.





      ________________________________
      From: Douglas Crockford <douglas@...>
      To: jslint_com@yahoogroups.com
      Sent: Thursday, May 28, 2009 10:11:55 AM
      Subject: [jslint] Global variables

      I have been working with strict mode in ES5. It requires that there be a var declaration if a program unit creates a new global variable. Implied global variables are not tolerated.

      If you have multiple files that could create the same global variable, then you must declare the var in every file.

      "use strict";
      var MY_GLOBAL;
      MY_GLOBAL = MY_GLOBAL || {};



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

      Yahoo! Groups Links



      [Non-text portions of this message have been removed]
    • pauanyu
      ... Personally, I will hardly notice any difference. Right now it s recommended to write your global variables like this: use strict ; /*global MY_GLOBAL */
      Message 2 of 3 , May 28, 2009
      • 0 Attachment
        --- In jslint_com@yahoogroups.com, Michael Lorton <mlorton@...> wrote:
        >
        > Woot!
        >
        > I think.
        >
        > The inconvenience of declaring globals in every file might drive developers to use proper namespaces. Or it might just suck.
        >

        Personally, I will hardly notice any difference. Right now it's recommended to write your global variables like this:

        "use strict";
        /*global MY_GLOBAL */
        MY_GLOBAL = MY_GLOBAL || {};

        You'll note that the current way is actually more verbose than the new way.
      Your message has been successfully submitted and would be delivered to recipients shortly.