Is there anyway to treat a string as a function name? To make something like this work(it doesn't)
Code:somestring = 'function_name';
window.onload = somestring
function function_name(){
}
Printable View
Is there anyway to treat a string as a function name? To make something like this work(it doesn't)
Code:somestring = 'function_name';
window.onload = somestring
function function_name(){
}
I think JavaScript doesn't allow any such feature like PHP
Not quite. However, when you define a global function or variable, it becomes a property of the global object. From here, you can access it by its name using the ECMAScript objects-as-associative-arrays idea:Code:var somestring = 'function_name';
window.onload = window[somestring];
function function_name(){}
Thanks Twey! Exactly what I was looking for.
hmmm thats a new thing for me thanks for the info Twey