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

"Global violation."

Expand Messages
  • pauanyu
    Now, I fully understand the reasons behind this change, and I approve. However, I ve noticed something interesting. If you select the Assume a browser
    Message 1 of 5 , Jun 5, 2009
    • 0 Attachment
      Now, I fully understand the reasons behind this change, and I approve.

      However, I've noticed something interesting. If you select the "Assume a browser" option, then try to assign to a predefined global variable, you get the "Global violation." error! Here's an example:

      location = 0;
      alert = 10;

      If I'm reading this correctly, the "Assume a browser" mode is the same as declaring the default global variables with var, so why is this throwing a "Global violation." error?
    • Douglas Crockford
      ... I don t understand your question. Are you saying that you want to change those global variables?
      Message 2 of 5 , Jun 5, 2009
      • 0 Attachment
        --- In jslint_com@yahoogroups.com, "pauanyu" <pcxunlimited@...> wrote:
        > If you select the "Assume a browser" option, then try to
        > assign to a predefined global variable, you get the "Global
        > violation." error! Here's an example:
        >
        > location = 0;
        > alert = 10;
        >
        > If I'm reading this correctly, the "Assume a browser" mode is
        > the same as declaring the default global variables with var,
        > so why is this throwing a "Global violation." error?

        I don't understand your question. Are you saying that you want to change those global variables?
      • pauanyu
        ... Yes. This works: var location = 0; var alert = 10; But this doesn t: location = 0; alert = 10; ...except the Assume a browser mode is supposed to already
        Message 3 of 5 , Jun 5, 2009
        • 0 Attachment
          --- In jslint_com@yahoogroups.com, "Douglas Crockford" <douglas@...> wrote:
          >
          > I don't understand your question. Are you saying that you want to change those global variables?
          >

          Yes.

          This works:

          var location = 0;
          var alert = 10;

          But this doesn't:

          location = 0;
          alert = 10;

          ...except the "Assume a browser" mode is supposed to already supply the default variables with the var statement, as per the JSLint Help file.
        • pauanyu
          ... Perhaps I was not clear enough. Allow me to quote the JSLint Help documentation: Some globals can be predefined for you. Select the Assume a browser
          Message 4 of 5 , Jun 5, 2009
          • 0 Attachment
            --- In jslint_com@yahoogroups.com, "Douglas Crockford" <douglas@...> wrote:
            >
            > I don't understand your question. Are you saying that you want to change those global variables?
            >

            Perhaps I was not clear enough. Allow me to quote the JSLint Help documentation:


            "Some globals can be predefined for you. Select the Assume a browser (browser) option to predefine the standard global properties that are supplied by web browsers, such as document and alert. It has the same effect as this statement:

            var alert, blur, clearInterval, clearTimeout, close, closed, confirm, console, Debug, defaultStatus, document, event, focus, frames, getComputedStyle, history, Image, length, location, moveBy, moveTo, name, navigator, onblur, onerror, onfocus, onload, onresize, onunload, open, opener, opera, Option, parent, print, prompt, resizeBy, resizeTo, screen, scroll, scrollBy, scrollTo, setInterval, setTimeout, status, top, XMLHttpRequest;"


            Let's test that statement. I will first try to change the predefined global variables "location" and "alert":


            location = 0;
            alert = 1;


            This fails in JSLint with the "Global violation." error. Now, let's run the same code, but put the big var block at the beginning:


            var alert, blur, clearInterval, clearTimeout, close, closed, confirm, console, Debug, defaultStatus, document, event, focus, frames, getComputedStyle, history, Image, length, location, moveBy, moveTo, name, navigator, onblur, onerror, onfocus, onload, onresize, onunload, open, opener, opera, Option, parent, print, prompt, resizeBy, resizeTo, screen, scroll, scrollBy, scrollTo, setInterval, setTimeout, status, top, XMLHttpRequest;

            location = 0;
            alert = 1;


            Note that JSLint does not give a "Global violation." error. As such, either JSLint is wrong, or the documentation is wrong.
          • pauanyu
            ... Here is another example of why JSLint is in error: onblur = function () {}; onload = function () {};
            Message 5 of 5 , Jun 7, 2009
            • 0 Attachment
              --- In jslint_com@yahoogroups.com, "Douglas Crockford" <douglas@...> wrote:
              >
              > I don't understand your question. Are you saying that you want to change those global variables?
              >

              Here is another example of why JSLint is in error:

              onblur = function () {};
              onload = function () {};
            Your message has been successfully submitted and would be delivered to recipients shortly.