tags:

views:

68

answers:

2

Is it possible to store the name of a function as string in JS, and invoke it from an object, pretty much like the PHP code below?

$this->$someFunc();
+13  A: 
this[someFunc]();
troelskn
+7  A: 

Sure thing. Try this:

var f = "foo";
var result = obj[f]();

where foo is a method on obj, or

this[f]();

where foo is a method on the current instance.

John Feminella