[Javascript] defining functions before they're called
John Warner
john at jwarner.com
Thu Aug 20 13:54:21 CDT 2009
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
More information about the Javascript
mailing list