This project is read-only.
1

Closed

ignoring globals doesn't work inside closures

description

Hi,

I just realised that using the global statement to ignore globals doesn't work inside closures.

For example, in the following code the second call to the method globalMethod shows me the warning "Use of implicitly declared global variable 'globalMethod'. But not in the first call.
/*global globalMethod */

globalMethod();
var myFunction = function () {
    'use strict';
    globalMethod();
};
This same code doesn't give errors in http://www.jslint.com/


This is a problem when using the jasmine test framework with code like the following:
/*global describe, it, expect */

describe("A suite", function () {
    'use strict';
    it("contains spec with an expectation", function () {
        expect(true).toBe(true);
    });
});
Cheers,
Asier
Closed Dec 4, 2013 at 9:41 AM by bleedo

comments

bleedo wrote Dec 4, 2013 at 9:40 AM

Hi asier,

The "Use of implicitly declared global variable 'globalMethod'" message is from Resharper, not JSLint.You can safely tell Resharper to ignore that error since JSLint captures it as "'globalMethod' was used before it was defined".

You can also tell JSLint for Resharper to override certain highlight they both catch by going to Resharper->JSLint for Resharper->Options and ticking "override resharper".However that won't work in this case, since JSLint doesn't report the variables you've put in the /global/ directive.

I'm closing this thread since it's a non-issue. I'll possibly write up some docs to show this, since it's the one most common "problem" reported. :)

HTH,Lars-Erik

asierba wrote Dec 9, 2013 at 10:40 AM

Hi Lars-Erik,

Ok, that makes sense. Many thanks.

Asier