对 Javascript 中未定义的 .function 进行最小条件检查

Minimal condition checking for.function undefined in Javascript

本文关键字:条件 检查 function Javascript 未定义      更新时间:2023-09-26

对不起,如果这个问题是以不同的方式提出的。基本上我必须写这个:

 (window.name ="xyz" && ahdframeset == ahdtop && typeof     
  window.parent.ahdframe.frames == "object" && typeof window.parent.ahdframe.frames  
 [window.name] == "undefined" ))

我必须主要检查是否定义了window.parent.ahdframe.frames[window.name].somefunction?与其验证对象和未定义,我可以使用类似的东西吗?

 (window.name ="xyz" && ahdframeset == ahdtop && typeof     
  window.parent.ahdframe.frames[window.name].somefunction == "undefined" )) 

并且不必担心Windows.parent.ahdframe为空或未定义时的JavaScript错误

你不能只是"不担心JavaScript错误"。 您必须测试属性以查看它们是否为空。

(window.name ="xyz" && ahdframeset == ahdtop && 
  window.parent && window.parent.ahdframe && window.parent.ahdframe.frames && window.parent.ahdframe.frames[window.name] &&
  typeof window.parent.ahdframe.frames[window.name].somefunction == "undefined" ))