"nybble" wrote
I'm trying to work on something wierd and was wondering, given a string
that contains the name of a function, can you get a reference to that
function? Any pointers are greatly appreciated. TIA.
Two possibilities come to mind: one using eval and one looking into the
window's properties, which all global variables including functions and
other objects belong to. The following should explain itself:
<script src="" type="text/javascript">//<![CDATA[
function fun() { window.alert( 'Hi!' ); }
window.alert( typeof window[ 'fun' ] ); // function
var tmp = eval( 'fun' );
window.alert( typeof tmp ); // function
tmp(); // Hi!
//]]></script>
hth
ivo
http://4umi.com/