1

I'd like to enumerate through all the global objects. This includes ones like HTMLElement, SVGAnimatedPreserveAspectRatio, and CameraControl. All of the answers I've seen for this problem have you iterating through window or the global object (obtained via tricks like this outside a namespace). However these tricks do not list the element, even though it is contained in window!

Here's some console log, but if you put it in a test .html page, you get the same result.

> HTMLElement
[object Function]
> window['HTMLElement']
[object Function]
> 'HTMLElement' in window
true
> for(var name in window){if(name == "HTMLElement")console.log('Found it!');}
undefined
> for(var name in window){if(name == "sessionStorage")console.log('Found it!');}
"Found it!"

How can I enumerate through all the global objects?

1
  • var a = Object.getOwnPropertyNames(window); -> a.indexOf("HTMLElement") -> 475 (for me) Commented May 7, 2014 at 13:41

1 Answer 1

1

You can iterate over all global objects like this:

var arr = Object.getOwnPropertyNames(window);
for(var i = 0; i < arr.length; i++){
   window[arr[i]]; // do something
}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.