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

2035Re: [jslint] Re: has not been fully defined yet

Expand Messages
  • John Hawkinson
    Mar 9, 2011
    • 0 Attachment
      Kent Davidson <kent@...> wrote on Wed, 9 Mar 2011
      at 14:12:41 -0500 in <46D9D4DF-08B8-4820-AE1F-179966621208@...>:

      > Which is an error, unless you want it to be "undefined".
      > The solution is simply to add a semicolon and repeat the variable.

      Wait, is this not bad advice?

      You are rewriting the code from a form JSLint detects as bad to a form
      that is equally bad, but escapes JSLint's detection because it is too
      hard to detect. In essence, you are encouraging programmers to defeat
      the limited forms of checking we have with a construct that can easily
      evolve later. Especially in Javascript where we lack block scope and
      JSLint encourages us (onevar: true) to declare variables far from
      their point of use.

      > var pdfdone;
      > pdfdone = doc.eventListeners.add("afterExport", function(e) {
      > if (e.format==="whatever") {
      > pdfdone.remove();
      > }

      This seems a classic case of the Law of Unintended Consequences. JSLint
      encouraging us to write code it cannot check to defeat its warning?

      In what's ironic, though, I had actually misinterpretted the problem
      in my actual code, because it actually did separate the declaration
      from point-of-use. But there was a typo in the declaration so the
      variable was implicitly global, and when I built a small test-case to
      understand JSLint's behavior, I inadvertantly fixed the typo.

      John Hawkinson
    • Show all 24 messages in this topic