javascript using string of function name to call function
Snippet
Instead of being asleep at 15:22 on 3 December 2009, kitt created this:
Have a string of a function name and want to call the function whose name is the string.
// Consider: var searchFn = "fnCallBack"; // want to do this (which fails) searchFn(name); // use this: eval(searchFn)(name); // or this: var fn = new Function("term", "return " + searchFn + "(term);"); fn(name); // be calling this: fnCallBack(name);
Source:
Add new comment