Python dir()在JavaScript中等效?

时间:2013-06-29 14:23:40

标签: javascript python

我喜欢Python的是,如果你想了解某个特定模块的某些内容,你可以这样做:

dir(django.auth.models)

它会为你提供models内的所有内容,在JavaScript中是否有类似内容?

3 个答案:

答案 0 :(得分:10)

您可以使用Object.keys(),例如:

> Object.keys(window)
["top", "window", "location", "external", "chrome", "Intl", "v8Intl", "document", "$", "jQuery", "MSIsPlayback", "i", "prepareEditor", "StackExchange", "scriptSrc", "careers_adurl", "careers_cssurl", "careers_leaderboardcssurl", "careers_companycssurl", "careers_adselector", "_gaq", "_qevents", "jQuery171008060155878774822", "__qc", "quantserve", "uh", "_gat", "gaGlobal", "gauth", "genuwine", "moveScroller", "styleCode", "sanitizeAndSplitTags", "initTagRenderer", "showFadingHelpText", "initFadingHelpText", "profileLink", "EventEmitter", "votesCast", "tagRendererRaw", "tagRenderer", "ytCinema", "IN_GLOBAL_SCOPE", "prettyPrintOne", "prettyPrint", "PR_SHOULD_USE_CONTINUATION", "PR", "Markdown", "apiCallbacks"]

答案 1 :(得分:1)

如果您在javascript中执行console.log(variable),您将在浏览器的调试控制台中看到有关该变量的信息。例如,如果变量是一个对象,您将看到它的属性。

答案 2 :(得分:0)

我不知道2013年是否没有此选项,但今天我们有了:

console.dir(variable)

ps:这个答案是针对那些在搜索“ javascript中的python目录”之后遇到的(就像我一样!)的人。