Last active
December 13, 2015 20:39
-
-
Save jcready/4972031 to your computer and use it in GitHub Desktop.
Detect Global Variables
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(){ | |
var differences = {}, | |
ignoreList = (prompt('Ignore filter (comma sep)?', 'jQuery, Backbone, _, $').split(/,\s?/) || []), | |
iframe = document.createElement('iframe'), | |
count = 0; ignoreList.push('prop'); | |
for (prop in window) { | |
differences[prop] = { | |
type: typeof window[prop], | |
val: window[prop] | |
}; count++; | |
} | |
iframe.src = 'about:blank'; | |
iframe.style.display = 'none'; | |
document.body.appendChild(iframe); | |
iframe = iframe.contentWindow || iframe.contentDocument; | |
for (prop in differences) { | |
if (prop in iframe || ignoreList.indexOf(prop) >= 0) { | |
delete differences[prop]; | |
count--; | |
} | |
} | |
console.info('Total globals: %d', count); | |
return differences; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment