简体   繁体   中英

How can I pass jslint and pass the global variable to my IIFE?

jslint does not like this .

}(this));

but it is how I pass the global variable to my IIFE which runs on both the client and server.

How can I change it?

I want to pass jslint with no options set.

It requires jumping through a fair number of hoops, but you can define this function, which passes JSLint and returns a reference to the global object:

function getGlobal() {
    // just creating a function here so that we can get at the Function constructor
    // via noop.constructor
    var noop = function () {
        // dummy statements so the linter doesn't complain about an 
        // empty block or unused variables
        var a = null;
        return a;
    };

    return noop.constructor("return this")();
}

Note that this function itself does not need to be defined in the global scope. You can define it and call it within your IIFE.

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