How to check if anonymous object has a method?

前端 未结 6 1822
遥遥无期
遥遥无期 2020-12-23 20:15

How can I check if an anonymous object that was created as such:

var myObj = { 
    prop1: \'no\',
    prop2: function () { return false; }
}
6条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-23 20:27

    One way to do it must be if (typeof myObj.prop1 != "undefined") {...}

提交回复
热议问题