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

Re: "Global violation."

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