سؤال

I have noticed a big amount of variables in my code leaked into global namespace. Is there a way to automatically find such leakages and report their position in the code?

I thought that code quality tools like jslint / jshint would be able to help me, but looking through their documentation I was not able to find anything related to this (although it looks like it should exist). I was not able to find a lot of information with keywords as in my title on google. One of the few relevant findings was this post from 2009.

هل كانت مفيدة؟

المحلول

The JSLint online tool shows you what globals are there

Screenshot of JSLInt.com example

نصائح أخرى

Maybe do something like this

for (var inGlobalScope in window) {
        console.log(inGlobalScope);
    }

Then go through the list of log entries to determine what shouldn't be in the global scope.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top