[Javascript] defining functions before they're called

Alexander Freiria xandercoded at gmail.com
Thu Aug 20 14:01:56 CDT 2009


+1 for Paul

On Thu, Aug 20, 2009 at 2:54 PM, John Warner <john at jwarner.com> wrote:

> You can run into a problem if the browser has not yet loaded or
> 'processed' that portion of the page that contains your function. Aside
> from that I think it is a matter of what you prefer and think most
> readable and maintainable
>
> John Warner
>
>
> > -----Original Message-----
> > From: javascript-bounces at lists.evolt.org [mailto:javascript-
> > bounces at lists.evolt.org] On Behalf Of Paul Novitski
> > Sent: Thursday, August 20, 2009 2:05 PM
> > To: JavaScript List
> > Subject: [Javascript] defining functions before they're called
> >
> > Can you think of a reason why one shouldn't call a function before
> > it's declared in the source code? For example:
> >
> >          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. 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. But I'm curious to know if any of you has ever
> > encountered a problem doing so.
> >
> > Regards,
> >
> > Paul
> > __________________________
> >
> > Paul Novitski
> > Juniper Webcraft Ltd.
> > http://juniperwebcraft.com
> >
> > _______________________________________________
> > Javascript mailing list
> > Javascript at lists.evolt.org
> > http://lists.evolt.org/mailman/listinfo/javascript
>
>
> _______________________________________________
> Javascript mailing list
> Javascript at lists.evolt.org
> http://lists.evolt.org/mailman/listinfo/javascript
>



-- 
Regards!

Alexander Freiria - Programmer\Web Developer
http://www.xandercs.com/
xandercoded at gmail.com
954.549.3666



More information about the Javascript mailing list