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

[jslint] Re: option.undef

Expand Messages
  • Aseem
    Good post, I agree. Just a quick note -- ... Yes, this will work: bar(); function bar () { // ... } But I said it feels wrong, because in terms of
    Message 1 of 9 , Dec 4, 2009
    • 0 Attachment
      Good post, I agree. Just a quick note --

      > > In this case, bar() will never be called before it's truly defined.
      >
      > Nor will it in the first example. Function declarations are hoisted,
      > which means that 'bar' is guaranteed to be available before the first
      > statement in a script is executed.

      Yes, this will work:

      bar();
      function bar () {
      // ...
      }

      But I said it "feels" wrong, because in terms of readability, it's not obvious that it works. A new Javascript developer might consider it a bug and try to "fix" it.

      Incidentally, it's vulnerable to breaking if the function declaration is tweaked:

      bar();
      var bar = function () {
      // ...
      };

      That's why I understand the intent of the option, but in general, I agree with you that it's a very inconvenient warning that often makes scripts *harder* to read.

      I was mainly differentiating between my two examples because if bar() is called from within another function, it no longer seems "wrong" in any language, to any developer, because it's clear that bar() isn't being called immediately. I.e. it's no longer top-down programming.

      Aseem
    • Stefan Weiss
      Hello Aseem. I agree with your post, except for one nitpick: ... That isn t a function declaration, so it won t be hoisted, and it won t be available at
      Message 2 of 9 , Dec 4, 2009
      • 0 Attachment
        Hello Aseem.

        I agree with your post, except for one nitpick:

        On 04/12/09 19:09, Aseem wrote:
        > Incidentally, it's vulnerable to breaking if the function declaration is tweaked:
        >
        > bar();
        > var bar = function () {
        > // ...
        > };

        That isn't a function declaration, so it won't be hoisted, and it won't
        be available at runtime. It's a function *expression*.

        ACK, otherwise.

        cheers,
        stefan
      Your message has been successfully submitted and would be delivered to recipients shortly.