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

Re: /*global */

Expand Messages
  • crlender
    ... Does that mean that we can t have two or more files that access the same global variable without explicitly declaring it in each and every file? For
    Message 1 of 34 , May 31, 2009
    • 0 Attachment
      --- In jslint_com@yahoogroups.com, "Douglas Crockford" <douglas@...> wrote:
      > I will be removing the /*global */ declarative comment. I am
      > persuaded that it is best to explicitly use var to declare all global
      > variables, even when accessing variables created by other compilation
      > units.
      >
      > /*global */ will just be a comment.

      Does that mean that we can't have two or more files that access the
      same global variable without explicitly declaring it in each and
      every file? For example:

      // file1.js
      var myNameSpace = {
      prop1: ...,
      prop2: ...
      };

      // file2.js
      myNameSpace.prop3 = {
      subprop1: ...,
      subprop2: ...
      }

      This is a very common situation. Up until now we could just tell
      JSLint to consider myNameSpace as global in file2.js. What's the
      advantage of removing /*global */? People who used it were already
      aware that undeclared globals are a bad idea, but now they don't
      have any recourse except to re-declare all global variables, again,
      in every file. Add to that the possibility that those files are
      automatically combined before they're sent to the client; re-declaring
      all globals would just litter the resulting script with duplicated
      var statements.

      Would it be possible to at least leave this as an optional feature?


      - Conrad
    • Douglas Crockford
      ... Which do you think is more likely, that a program wants to change the global name, or that a var name declaration in a function was forgotten? We won t get
      Message 34 of 34 , Jun 12, 2009
      • 0 Attachment
        --- In jslint_com@yahoogroups.com, "pauanyu" <pcxunlimited@...> wrote:
        > "name" needs to be writable. It has no value by default,
        > but you can assign a string to it, indicating the name of
        > the window/tab.

        Which do you think is more likely, that a program wants to change the global name, or that a var name declaration in a function was forgotten? We won't get an implied global warning, but at least we can get a read only warning. I think that is the more useful default.
      Your message has been successfully submitted and would be delivered to recipients shortly.