[Javascript] looping through nodeList

Paul Novitski paul at novitskisoftware.com
Tue Oct 18 15:22:14 CDT 2005


At 12:55 PM 10/18/2005, Anthony Ettinger wrote:
>window.onload=Name();
>
>Needs to be without the ()'s:
>
>window.onload=Name;
>
>..which makes sense, since you wouldn't be passing
>parameters from anywhere on the initial routine call.


The way I think of this:

         window.onload = DoSomething;

is that the entire text of the function DoSomething() is copied to 
the window.onload "variable."  If you then execute:

         alert(window.onload);

you'll see the DoSomething() function script there in its entirety.

One interesting ramification of this (which I've played with in other 
languages but never in javascript) is the feasibility of parsing and 
modifying function code stored in a variable.  For example, a 
function can edit a copy of itself and then call this revised form of 
itself.  Nasty-fun wrinkle on recursion!  Those kinds of games can 
produce program code that's incredibly difficult to maintain, but 
it's fun to play with nonetheless.

Paul 




More information about the Javascript mailing list