I wand to check for the existence of a JavaScript method, when I have a variable with that method name inside it.
使用购买力平价 我可以这样做:
$method = bar ;
$object = new Foo;
if(method_exists($object, $method))
{
//Foo->bar()
}
我如何在 Java山这样做? 我的第一次尝试失败了:
var method = bar ;
if(typeof(obj.method) != "undefined")
{
obj.method();
}
else
{
obj.default();
}