[Javascript] defining functions before they're called

Alexander Freiria xandercoded at gmail.com
Thu Aug 20 14:52:17 CDT 2009


Where does it stipulate that this is bad practice?

On Thu, Aug 20, 2009 at 3:50 PM, Alexander Freiria <xandercoded at gmail.com>wrote:

> Your wrong Brian that will work.
>
> On Thu, Aug 20, 2009 at 3:26 PM, Brian L. Matthews <blmatthews at gmail.com>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. You have to
>> define any identifier before you use it, except the case where you're
>> assigning to it, in which case it's made a global if not already defined
>> (and although it works, it's considered bad practice).
>>
>> Brian
>> _______________________________________________
>> 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
>



-- 
Regards!

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



More information about the Javascript mailing list