How to find all the JavaScript globals in browser code which are not part of the DOM, host objects, etc?

139 views Asked by At

In JavaScript in the browser global variables are stored as members of the window host object.

But also in window are all the properties of window which are part of the browser DOM and, if I assume correctly, other global functions and objects which are also host objects or otherwise part of the implementaton / environment provided by the browser.

How can I iterate through the members of window and filter out as much as possible everything that is not just a regular global variable created by code such as var foo = 1;?

1

There are 1 answers

5
Tushar On

Why don't you try:

keys(window);

The Object.keys() method returns an array of a given object's own enumerable properties, in the same order as that provided by a for...in loop (the difference being that a for-in loop enumerates properties in the prototype chain as well).

Reference: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys