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

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

Expand Messages
  • John Hawkinson
    Mar 9, 2011
      > No, it isn't. Declare the variable before giving it a value that
      > depends on the same variable. It is easy.

      This is a bit more troublesome for event handlers.

      Leaving the browser world for a moment, I encountered this morning:

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

      Which hits:

      Problem at line 4 character 7: 'pdfdone' has not been fully defined yet.

      Am I required to give up the anonymous function paradigm? It's very
      nice to not have to bind a name to this function. But in this API, the
      only way I have to remove the event handler is to invoke a property
      returned from adding the event handler.

      Is there anything short of:

      (function() {

      var pdfdone;

      function handler(e) {
      if (e.format==="whatever") {
      pdfdone.remove();
      }
      // ...
      }

      pdfdone = doc.eventListeners.add("afterExport", handler);
      }());

      That makes me somewhat unhappy. Could we have a
      /*jslint*/ directive so I can mark that function scope as being safe
      for this?


      (Philosophically, I am a bit puzzled why JSLint doesnt
      have a /*LINTED*/ equivalent for single lines. Would it
      really encourage such bad programming?)

      --jhawk@...
      John Hawkinson
    • Show all 24 messages in this topic