I did a little search, but this particular problem is a bit like "how I evaluate function names from strings", so itβs hard for me to find a solution, I want to convert the string to a function so to speak, I had something like:
for (var i = 0; i < someNumber ; i++) { var foo = "function() { someObject.someOtherFunctionCall(" + i + ") }"; someArray[i] = foo; }
how would i draw foo so i can call
someArray[0]();
I need a value baked in a function, any ideas?
EDIT: I just replaced the "value" with the "i" apology for the confusion
UPDATE:
Ok, I accepted icktoofay's answer because it works to answer most of your questions and concerns; I tried most of the proposed methods, which either did not pass the scope variable of the calls or did not require closing, which were stored with the last value of the function variable, unfortunately, I do not control the rest of the code, so I can not make changes to the location that the function in ultimately causes.
This is probably a workaround; I know how ugly syntax lines are for functions. as far as browser compatibility is concerned, this will only work in one environment, so I think we're pretty safe there.
Anyway, thanks for the tips and discussion.
source share