I wand to check for the existence of a JavaScript method, when I have a variable with that method name inside it.
Using PHP I could do this:
$method = 'bar';
$object = new Foo;
if(method_exists($object, $method))
{
//Foo->bar()
}
How can I do this in JavaScript? My first attempt failed:
var method = 'bar';
if(typeof(obj.method) != "undefined")
{
obj.method();
}
else
{
obj.default();
}