Reputation: 949
I have two classes in jquery e.g:
function a(){
this.init = function(a){}
}
function b(){
this.init = function(a){}
}
Both the classes have this.init() method.I have a situation that i have the object of both classes and i want to call init() method of class b how can i know the name of the custom object so that i can easily call the init() method of class b like
if (current_object == typeof b)
current_object.init()
Upvotes: 2
Views: 471
Reputation: 24354
you can use constructor
property of the objects
var obj = new b();
console.log(obj.constructor == b);
console.log(obj.constructor == a);
In action: http://jsfiddle.net/9j3HJ/
for b()
object
if (current_object.constructor == b)
current_object.init();
Upvotes: 1
Reputation: 8346
Use instanceof,
if (current_object instanceof b)
current_object.init()
Upvotes: 5