In the window
object there are variables and other properties and constructors like Array
, Object
etc).
Is there any possibility to list the global variables that were created by a script?
e.g.
// after including jQuery
foo() // => ["$", "jQuery"]
My first assumption would be to create a list with properties created by the browser:
var bList = ["Object", "Array" ...];
And then we can do:
var v = [];
for (var k in window) {
if (bList.indexOf(k) === -1) {
v.push(k);
}
}
return v;
Also, this will not catch the case when a property is overridden.
Is there any better solution?