-1

Referring to below question Iterate through object properties

If I want to iterate the object to search one function(given a function name in a variable) and then make a call to that function. How can I do it? I mean dynamically calling the function.

var libName = ''; //Get JS Library name from other source
var funName = ''; // Get function name from other source
var util = $.import("pathToJSLib",libName);
util.{call to function funName} // Call to function in funName
Community
  • 1
  • 1
mike
  • 21
  • 1
  • 1
  • 2

2 Answers2

1

You can call it like this: util[funName]()

Lee
  • 2,993
  • 3
  • 21
  • 27
0

You can use square bracket notation:

util[funName]();
VisioN
  • 143,310
  • 32
  • 282
  • 281