views:

377

answers:

6

Hello everyone.

In Firebug the DOM tab shows a list of all your public variables and objects. In Chrome's console you have to type the name of the public variable or object you want to explore. Is there a way - or at least a command - for Chrome's console to display a list all the public variables and objects? It will save a lot of typing.

Thank you all Stefanos

A: 

The window object contains all the public variables, so you can type it in the console.

Fabien Ménager
A: 

As all "public variables" are in fact properties of the window object (of the window/tab you are looking at), you can just inspect the "window" object instead. If you have multiple frames, you will have to select the correct window object (like in Firebug) anyway.

mihi
Thank you all!!!
GRboss
+4  A: 

Is this the kind of output you're looking for?

for(var b in window) { 
  if(window.hasOwnProperty(b)) console.log(b); 
}

This will list everything available on the window object (all the functions and variables, e.g. $ and jQuery on this page, etc). Though, this is quite a list, not sure how helpful it is...

Otherwise just do window and start going down it's tree:

window

This will give you DOMWindow, an expandable/explorable object.

Nick Craver
DOMWindow doesn't have a `hasOwnProperty` method.
ntownsend
@ntownsend -My console disagrees with you :) [It's a property of `object`](https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Object/hasOwnProperty), why wouldn't it have it?
Nick Craver
@Nick Craver - Withdrawn. When I posted the above comment, I did a test in my console that showed `window` had no `hasOwnProperty` method. Indeed, at that time, it didn't. I've just checked again, after reading your response, and my console now agrees that `window` has such a method. Mysterious.
ntownsend
"why wouldn't it have it?" The `[[Prototype]]` internal property of the global object is *implementation dependent*, in almost all major implementations -V8, Spidermonkey, Rhino, etc-, the global object inherits at some point from `Object.prototype`, but for example in other implementations -JScript, BESEN, DMDScript, etc...- it doesn't, so `window.hasOwnProperty` doesn't exist, to test it we can: `Object.prototype.isPrototypeOf(window);`
CMS
@CMS - Yes that's true...but the question is specifically about Chrome, so the implementation is known.
Nick Craver
@Nick, yeah, just added it as a note because the fact is not well known...
CMS
@CMS - Fair point, this is sure to come up in google for lots of other searches, +1 from me.
Nick Craver
+1  A: 

You may want to try this Firebug lite extension for Chrome.

KooiInc
Though it does look nice, this solution sounds a bit of using a cannon to kill a mosquito to me.
Marcel Korpel
Maybe. It's the only thing I found that shows objects/functions/etc. the way firebug in FF does (under the DOM-tab in the extension). It's a bit slow though.
KooiInc
+4  A: 
Marcel Korpel
A: 

Thank you all

  1. type "window" at the console
  2. the screenshot above
GRboss