简体   繁体   中英

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

I tried to use jsHint on my project. 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. I use default settings for jsHint from http://jshint.com/ . 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!';
    }
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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