Javascript type of custom object

前端 未结 5 1443
春和景丽
春和景丽 2020-12-13 08:28

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

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

In the case above

5条回答
  •  一生所求
    2020-12-13 08:50

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

    if (s1 instanceof SomeObject) { ... }
    

提交回复
热议问题