[Javascript] defining functions before they're called

David Dorward david at dorward.me.uk
Thu Aug 20 15:01:04 CDT 2009


On 20 Aug 2009, at 20:26, Brian L. Matthews wrote:

> On 8/20/09 11:05 AM, Paul Novitski wrote:
>> 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()
>>          {
>>                  ...
>>          }
>
> First, you're not calling the function. Second, that won't work,
> JavaScript will complain that initialize is not defined.

No, it won't. It uses a function declaration, not a function statement  
or function constructor.

-- 
David Dorward
http://dorward.me.uk




More information about the Javascript mailing list