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

assume a browser doesn't imply global window object

Expand Messages
  • Arthur Blake
    /*jslint browser: true*/ window.onload = function () { document.getElementById( hello ).appendChild(document.createTextNode( world )); }; gives me: *Error:*
    Message 1 of 4 , May 7 5:24 AM
    • 0 Attachment
      /*jslint browser: true*/ window.onload = function () {
      document.getElementById("hello").appendChild(document.createTextNode("world"));
      };

      gives me:

      *Error:*

      *Implied global:* window *2*


      Why does Assume a browser option allow document, but not window?


      [Non-text portions of this message have been removed]
    • christian.wirkus
      ... There is a post that mentioned it: http://tech.groups.yahoo.com/group/jslint_com/message/475 In Javascript there is this global object hanging around
      Message 2 of 4 , May 7 8:58 AM
      • 0 Attachment
        --- In jslint_com@yahoogroups.com, Arthur Blake <arthur.blake@...> wrote:
        > Why does Assume a browser option allow document, but not window?

        There is a post that mentioned it:
        http://tech.groups.yahoo.com/group/jslint_com/message/475

        In Javascript there is this global object hanging around everywhere, without having a name to rely on; and in browsers it may appear with so many names (window, parent, self), I guess it's not healthy to allow a special one.

        Just stick with a single one and add it to your globals:
        /*global window */
      • Arthur Blake
        OK.. my bad. I remember seeing that earlier thread, but for some reason didn t connect the dots. It seems a little weird that window isn t assumed when
        Message 3 of 4 , May 7 11:00 AM
        • 0 Attachment
          OK.. my bad. I remember seeing that earlier thread, but for some reason
          didn't connect the dots.
          It seems a little weird that window isn't assumed when 'assume a browser' is
          checked because it is one of the variables that is so frequently used in a
          browser (maybe the point is that it shouldn't be so frequently used...)

          On Thu, May 7, 2009 at 11:58 AM, christian.wirkus <
          christian.wirkus@...> wrote:

          >
          >
          > --- In jslint_com@yahoogroups.com <jslint_com%40yahoogroups.com>, Arthur
          > Blake <arthur.blake@...> wrote:
          > > Why does Assume a browser option allow document, but not window?
          >
          > There is a post that mentioned it:
          > http://tech.groups.yahoo.com/group/jslint_com/message/475
          >
          > In Javascript there is this global object hanging around everywhere,
          > without having a name to rely on; and in browsers it may appear with so many
          > names (window, parent, self), I guess it's not healthy to allow a special
          > one.
          >
          > Just stick with a single one and add it to your globals:
          > /*global window */
          >
          >
          >


          [Non-text portions of this message have been removed]
        • Douglas Crockford
          ... Write onload = function (e) {...}; instead. The window is superfluous. ... Because global variables are evil, and window is the container of all global
          Message 4 of 4 , May 7 11:17 AM
          • 0 Attachment
            --- In jslint_com@yahoogroups.com, Arthur Blake <arthur.blake@...> wrote:
            >
            > /*jslint browser: true*/ window.onload = function () {
            > document.getElementById("hello").appendChild(document.createTextNode("world"));
            > };

            Write

            onload = function (e) {...};

            instead. The window is superfluous.

            > Why does Assume a browser option allow document, but not window?

            Because global variables are evil, and window is the container of all global variables. Dependence on global variables introduces unreliability, insecurity, and weakness. You don't want superfluous badness in your code, do you?
          Your message has been successfully submitted and would be delivered to recipients shortly.