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

Re: [jslint] Re: assume a browser doesn't imply global window object

Expand Messages
  • 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 1 of 4 , May 7, 2009
    • 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 2 of 4 , May 7, 2009
      • 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.