jslint should watch only global variables

81 views Asked by At

I'm trying to use online lint from http://www.jslint.com/. I also tried using webstorm. I want to get only the global variables. however, my code is very long (about 30000 lines) and it scans only 1% of it. Is there any way to use lint, or another tool to find only the global variables (the rest is not important for me). My goal is to get all global variables attached to the window object.

1

There are 1 answers

1
ruffin On BEST ANSWER

If you're able to run this script after the file's "initialized" (that is, if you're looking for what's on the global object after load), you can run something like this...

for (value in window) { 
    if (window.hasOwnProperty(value)) {
        if (console.log) console.log(value);
    }
}

Keep in mind that code can wait to add things to the global scope until it's called, so you could get more in the global context after more interaction with your code.

In a browser context, the window is the global object, so anything hanging off of it is in your global context. In other contexts, it can be different -- in node, eg, it's apparently global.

Allardice explains why you want hasOwnProperty in some detail here. In brief, hasOwnProperty will limit you to properties on the object itself, without traipsing down the object's prototype chain. Even more briefly, using hasOwnProperty will cut out some of the cruft that wasn't added by your code to the object (in this case, the global window context).