javascript using string of function name to call function
Snippet
kitt decided around 15:22 on 3 December 2009 to publish 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