0

this is an example function:

function processFanGrowth() {
    console.log('fanGrowth');
}

and an object "data" which has a property name "FanGrowth"

for(var property in data) {
      // here i'm trying to generate the function name.
      funcName = "process" + property;
      funcName();
}

i'm getting this error: Uncaught TypeError: string is not a function

tareq
  • 1,119
  • 6
  • 14
  • 28

2 Answers2

5

You can invoke the function as a property of the object whose scope it is defined in, e.g. for a function defined in global scope:

window['process' + property]();
Lightness Races in Orbit
  • 369,052
  • 73
  • 620
  • 1,021
0

This syntax should work:

window["functionName"](arguments);

In your case:

for(var property in data) {
      // here i'm trying to generate the function name.
      funcName = "process" + property;
      window["functionName"]();
}
Husman
  • 6,579
  • 7
  • 28
  • 46