简体   繁体   English

为什么jsHint无法检测到“未定义”错误?

[英]Why jsHint doesn't detect an error “is undefined”?

I tried to use jsHint on my project. 我尝试在项目上使用jsHint。 But for me it doesn't work obviously. 但是对我来说,它显然不起作用。 For example: 例如:

(function () {
    if (!window.myApp) window.myApp = {};
    var myApp = window.myApp;
    var a = function (key) {
        key = key || "key";
        return myApp.someModule.get(key);
    };

    a();
})();

This chunk should throw error, something like that: "TypeError: myApp.someModule is undefined", but jsHint is still silent. 该块应该引发错误,类似这样:“ TypeError:myApp.someModule未定义”,但是jsHint仍然保持沉默。 I use default settings for jsHint from http://jshint.com/ . 我使用来自http://jshint.com/的 jsHint的默认设置。 Can anybody help me? 有谁能够帮助我? Thanks a lot. 非常感谢。

Fairly sure that it only checks for variables in the "local" scope, it won't check all the way down objects chains. 一定要确保它只检查“局部”范围内的变量,而不是一直检查对象链。 In fact I'd say it's impossible to be able to detect in all cases. 实际上,我想说在所有情况下都无法检测到。

Consider: 考虑:

var o = {};
someAjaxRequest({
    callback: function(response) { 
        o[response.responseText] = 'found!';
    }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM