I want to check if the class has a method or not in javascript. Suppose for checking normal function I can use like -
Using Jquery:
function foo(){}
if($.isFunction(foo)) alert('exists');
Or from normal javascript:
function foo(){}
if(typeof foo != 'undefined') alert('exists');
But I want to check for a member function like if I have a class and method like-
function ClassName(){
//Some code
}
ClassName.prototype.foo = function(){};
And I have a method name stored in a variable, and I am calling the method using this variable like-
var call_it = 'foo';
new ClassName()[call_it]();
But for the handling runtime error, I want to check the method exist or not before calling. How can I do that?