4

I am experiencing a javascript bug in internet explorer and I suspect its due to a name of a div matching with a global object.

My application loads many javascript libraries.

I want to find what global objects are loaded at runtime

0

2 Answers 2

5

Since all user JS defined global objects/vars are properties of the window object, you can list all the enumerable ones with this:

for (var item in window) {
    console.log(item);
}

This will get you a list of a lot of things including all global functions. If you want to filter out global functions, you can use this:

for (var item in window) {
    var type = typeof window[item];
    if (type != "function") {
        console.log(item + " (" + type + ")");
    }
}
Sign up to request clarification or add additional context in comments.

5 Comments

thanks ,I actually what I was looking for was I got under DOM Tab in firebug.
This won't necessarily give you all properties. You'll only get enumerable ones.
@amnotiam - the point here was to get a list that includes all user JS global functions and vars and any global vars that the system might have defined (like those that mimic some named objects). Those will be in this list. Other window properties/methods may or may not be enumerable, so they may or may not be in the list, but that isn't what we're looking for here.
I know the OP asked about querying within the browser, but what is the equivalent within Node?
@colminator - Globals in node.js are on the global object. So, instead of iterating properties of the window object, you would iterate properties of the global object. Note, it's also possible to have global properties that are configured to not be enumerable so they wouldn't show up. And, as this is a really old answer, one may now want to use Object.keys(global) to get all the property names instead of for/in).
0

You can simply inspect the window object in Chrome/Firefox devtools: just type window in the devtools console and expand the object to view its members.

enter image description here

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.