View Full Version : Treat string as a function
10-17-2006, 10:10 PM
Is there anyway to treat a string as a function name? To make something like this work(it doesn't)
somestring = 'function_name';
window.onload = somestring
10-18-2006, 03:53 AM
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:
var somestring = 'function_name';
window.onload = window[somestring];
10-18-2006, 09:19 PM
Thanks Twey! Exactly what I was looking for.
10-19-2006, 03:59 AM
hmmm thats a new thing for me thanks for the info Twey
Powered by vBulletin® Version 4.2.0 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.