Created
July 28, 2015 12:03
-
-
Save tcelestino/3ddc37c7d4d778e2d249 to your computer and use it in GitHub Desktop.
Detecting var globals. Create by Remy Sharp
This file contains 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) { | |
function Globals () {} | |
var getWindow = function () { | |
var iframe = document.createElement('iframe') | |
iframe.style.display = 'none' | |
document.body.appendChild(iframe) | |
var result = iframe.contentWindow || iframe.contentDocument | |
iframe.parentElement.removeChild(iframe) | |
return result | |
} | |
Globals.prototype.get = function() { | |
var iframeWindow = getWindow() | |
var result = [] | |
var property; | |
// Window | |
for (property in global) { | |
if (!(property in iframeWindow)) { | |
result.push(property) | |
} | |
} | |
return result | |
}; | |
global.globals = new Globals(); | |
}(window)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment