> From: juliandormon
> 
> Is it possible to write javascript dynamically so new 
> functions are created with the new parameters once the user 
> makes a change? These functions need to be added to the head 
> of my page because they get called after other functions. In 
> other words, the new functions interact with the javascript 
> that's already on the page. I guess they could be written 
> elsewhere dynamically within a main function and I simply 
> call this remote function and thereby any sub  functions that 
> have been written to it. Is this possible?

JavaScript is a dynamic language. A *very* dynamic language. You can do
anything, any time.

JavaScript functions do not reside in the head nor the body of the document.
All global functions are actually properties of the window object. Where or
when you define them has no effect on that.

Consider this piece of code:

myfunction = function() { alert( 'hi!' ); };

You could execute that code in a script tag in the head, in a script tag in
the body, in a script that you load dynamically, or in a script that you
*create on the fly*. It will do the same thing regardless.

How about this one:

eval( "myfunction = function() { alert( 'hi!' ); };" );

That does exactly the same thing, but now you're using a string that you
could have generated any way you like.

If there is other code in the page that calls myfunction(), and you later
redefine myfunction, that existing code will start using your new function.

One exception: Suppose a piece of code does this, or something like it:

var savemyfunction = myfunction;

And then that code calls savemyfunction(). Code like that will not pick up
your new function definition, because it has already saved a reference to
the previous "myfunction".

I didn't look at your specific question about innerFade, I'm just addressing
the general question of defining functions dynamically.

-Mike

Reply via email to