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

Re: /*global */

Expand Messages
  • crlender
    ... Looking at an older version of jslint.js (2008-11-07), it has the ... The way I understand it, /*global*/ is normally used to disable warnings about
    Message 1 of 34 , Jun 1, 2009
    • 0 Attachment
      --- In jslint_com@yahoogroups.com, "Douglas Crockford" <douglas@...> wrote:
      > But working with ES5/strict, the JSLINT program itself passed
      > JSLint but failed to run. The failure due to my using a /*global */
      > comment instead of a var statement. So now it turns out that
      > /*global */ can mask errors from JSLint. That forces me to abandon
      > /*global */ and look for a more reliable approach.

      Looking at an older version of jslint.js (2008-11-07), it has the
      following lines at the beginning:

      | /*global JSLINT*/
      |
      | // We build the application inside a function so that we produce
      | // only a single global variable. The function will be invoked, its
      | // return value is the JSLINT application itself.
      |
      | "use strict";
      |
      | JSLINT = function () {

      The way I understand it, /*global*/ is normally used to disable
      warnings about undeclared globals, usually because the programmer
      knows that variable is defined elsewhere. I don't know why you used
      /*global*/ instead of "var" in this case, but it's not surprising
      that JSLint didn't warn you, because you actively told it to suppress
      the warning. Looks like it was working as intended.

      > This language continues to surprise me. I thought I had figured out
      > a good pattern for handling global variables. It turned out I was
      > wrong. I think this new pattern is better.

      The problem that some of us have with the removal of /*global*/ is
      that JSLint now demands declarations that were previously deemed bad
      style and actually caused a warning ("... is already defined").
      Silencing warnings in a lint checker is a conscious action, and
      indicates that the programmer knows something about the program that
      the checker can't know (i.e. the existence of other related files).
      Randall's point earlier in this thread (implicit predefined globals
      like HTMLElement and others) is also very relevant. How can we tell
      JSLint to accept these objects now?


      - 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.