为什么当我使用dojo.hitch函数并试图引用里面的“this”运算符时,它给了我引用错误的对象?Dojo.hitch()范围问题
console.debug(dijit.byId("widgetName")); //works as expected and prints out the window object
dojo.hitch(dijit.byId("widgetName"), tester())(); //this should be executing the tester function in the scope of the widget object
function tester() {
console.debug(this); //prints out the Javascript Window object instead of the widget object!!!!
}
感谢
这不应该发生,不要相信你发布的内容与你在应用程序中尝试的内容相同。任何scnreenshots支持它? – Layke
如果你把'console.log(dijit.byId(“widgetName”))'放在'hitch'之前,你确定它能够正确地返回吗?它是否会返回null?在这种情况下,'this'指的是'window'。 – pimvdb
@Layke我知道这不应该发生,因此我的问题。一段时间以来,我一直在挠头。这是完全从我的应用程序复制/粘贴代码。我不知道你想在截图中看到什么?! – Ayyoudy