Last active
June 6, 2016 15:47
-
-
Save Couto/5905674 to your computer and use it in GitHub Desktop.
Small snippet to 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 (global) { | |
'use strict'; | |
var globals = []; | |
var iframe = document.createElement('iframe'); | |
var cleanWindow; | |
iframe.src = 'about:blank'; | |
iframe.style.display = 'none'; | |
document.body.appendChild(iframe); | |
cleanWindow = Object.assign({}, iframe.contentWindow, iframe.contentDocument); | |
iframe.parentNode.removeChild(iframe); | |
globals = Object.keys(global) | |
.map(function (key) { if (!(key in cleanWindow) ) { return key; } }) | |
.filter(function (val) { return !!val; }) | |
.sort(); | |
console.log(globals.length, globals); | |
}(this)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment