如何解决如何检查匿名对象是否有方法??

typeof myObj.prop2 === 'function';将让您知道该功能是否已定义。

if(typeof myObj.prop2 === 'function') {
    alert("It's a function");
} else if (typeof myObj.prop2 === 'undefined') {
    alert("It's undefined");
} else {
    alert("It's neither undefined nor a function. It's a " + typeof myObj.prop2);
}

解决方法

如何检查是否创建了这样的匿名对象:

var myObj = { 
    prop1: 'no',prop2: function () { return false; }
}

确实定义了 prop2 吗?

prop2将始终定义为函数,但对于某些对象,它不是必需的,也不会被定义。