javascript - 如何在 dojo 或 JavaScript 中检查多个 undefined?

标签 javascript dojo undefined

我的项目中有以下代码。如您所见,我必须检查所有对象和属性的未定义 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/

相关文章:

javascript - 回到上次滚动位置——jquery移动页面设计

javascript - Dojo 水平范围 slider ,带 2 个输入字段

dojo - 如何隐藏 dijit/表单/按钮?

javascript - JSONP图像请求不循环?

javascript - 快速路线不起作用?

javascript - 如果未选择第一项jquery,则选择下拉菜单

javascript - 检查 Javascript 中的未定义

javascript - 使用带有 requireJS 的 Twitter Bootstrap - undefined 不是一个函数`

JavaScript - 'this.form' 返回未定义

javascript - 在页面加载时运行一些 JavaScript