回答

1

因为它应该是&&,即逻辑与

if (typeof callback != "undefined" && callback != null) { 
    callback(); 
} 

但我会建议使用检查型 “功能”:

if (typeof callback === "function") { 
    callback(); 
} 

甚至更​​短:

typeof callback === "function" && callback(); 
0

尝试:

console.log(callback); 
if (!(typeof (callback) == "undefined" || callback == null)){ 
    callback(); 
} 
相关问题