问题描述
在 Firebug 中,DOM 选项卡显示所有公共变量和对象的列表.在 Chrome 的控制台中,您必须输入要探索的公共变量或对象的名称.
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.
有没有办法——或者至少是一个命令——让 Chrome 的控制台显示所有公共变量和对象的列表?这将节省很多打字时间.
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.
推荐答案
这是您正在寻找的输出类型吗?
Is this the kind of output you're looking for?
for(var b in window) {
if(window.hasOwnProperty(b)) console.log(b);
}
这将列出 window
对象上可用的所有内容(所有函数和变量,例如,此页面上的 $
和 jQuery
等.)不过,这是一个相当多的清单;不确定它有多大帮助...
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...
否则只需执行 window
并开始沿着它的树向下移动:
Otherwise just do window
and start going down its tree:
window
这将为您提供 DOMWindow
,一个可扩展/可探索的对象.
This will give you DOMWindow
, an expandable/explorable object.
这篇关于在 Google Chrome 控制台中查看所有 JavaScript 变量的列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!