BjartN BjartN - 1 year ago 102
Javascript Question

Javascript type of custom object

How can I check if my javascript object is of a certain type.

var SomeObject = function() { }
var s1 = new SomeObject();

In the case above
typeof s1
will return "object". That's not very helpful. Is there some way to check if s1 is of type SomeObject ?

Answer Source

Yes, using instanceof (MDN link | spec link):

if (s1 instanceof SomeObject) { ... }
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download