我的项目中有以下代码。如您所见,我必须检查所有对象和属性的未定义 this.view && this.view.formView && this.view.formView._dapSections && this.view.formView._dapSections.scrollTop。
我正在寻找一种同时检查所有未定义的方法。在 JavaScript 或 dojo 中有什么方法可以做到这一点吗?
if(this.view && this.view.formView && this.view.formView._dapSections && this.view.formView._dapSections.scrollTop) {
globals.lastScrollPosition = this.view.formView._dapSections.scrollTop;
}
最佳答案
您可能还想试试 lang.exists() https://dojotoolkit.org/reference-guide/1.10/dojo/_base/lang.html#dojo-base-lang-exists
if (lang.exists('view.view.formView._dapSections.scrollTop', this) {
globals.lastScrollPosition = this.view.formView._dapSections.scrollTop;
}
关于javascript - 如何在 dojo 或 JavaScript 中检查多个 undefined?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33741024/