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

defining functions before they're used

Expand Messages
  • Paul Novitski
    jslint complains if I use a function before it s defined, e.g.: window.onload = initialize; function initialize() { ... } I can certainly understand why one
    Message 1 of 1 , Aug 20, 2009
    • 0 Attachment
      jslint complains if I use a function before it's defined, e.g.:

      window.onload = initialize;

      function initialize()
      {
      ...
      }

      I can certainly understand why one might choose, stylistically, to
      always define functions before calling them. However, I have never
      experienced any problem using JavaScript by putting the call before
      the function being called.

      Is this an instance of jslint merely recommending a coding style, or
      can there be compile-time or run-time problems resulting from putting
      the call before the function?

      (It's my personal preference to put the call first because I like to
      read scripts top-down, seeing how a function is used before reading
      the details of exactly what the function does.)

      Regards,

      Paul
      __________________________

      Paul Novitski
      Juniper Webcraft Ltd.
      http://juniperwebcraft.com
    Your message has been successfully submitted and would be delivered to recipients shortly.