I'm looking for a programmatic way to get a list of browser globals, including built-in constructors like Array
, Object
, etc.
If I type Javascript in the Chrome console, I get this somewhat odd behavior:
console.log('Array' in globalThis); // true
const s = new Set(function*() { for (const key in globalThis) yield key; }());
console.log(s.has('Array')); // false
That is, I can check if the Array
constructor is in the global object, but when I enumerate its members the Array
constructor is not there.
My questions:
Why doesn't my approach of enumerating keys work?
Is there a programmatic and cross-browser way (only evergreen browsers is okay) to enumerate every member accessible through globalThis
?
Failing that, are there programmatic browser-specific ways to accomplish this?