简体   繁体   中英

jshint no error for forin (hasOwnProperty)

Why jshint is not reporting forin (hasOwnProperty) error for the following code? jslint do report error on it but jshint doesn't.

/*jshint forin: true */

(function () {
    "use strict";

    var obj = {a: 1, b: 2}, i = null;

    for (i in obj) {
        if (i === 0) {
            console.log('blah...');
        }
    }
}());

Here's the relevant snippet of code from JSHint (modified slightly for formatting):

if (
    state.option.forin && 
    s && 
    (s.length > 1 || typeof s[0] !== "object" || s[0].value !== "if")
) {
    warning("W089", this);
}

The important part is s[0].value !== "if" . JSHint won't raise an error if the first statement of the for...in body is an if statement, regardless of the condition of that statement.

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