javascript - Making a function with a random name and calling it later -
so i'm trying make function have random name generated on page load, i'm having problems calling method later. got far:
var methodname = math.floor(math.random()*1000001); window[methodname] = function(){ alert("it works!"); } window.onload = function start() { methodname(); }
but i'm having problems calling it, since methodname();
random number. how call methodname()
function?
you can reference property same way set it:
window[methodname]();
Comments
Post a Comment