8

我喜欢 Python 的地方在于,如果你想了解某个特定模块的一些信息,你可以这样做:

dir(django.auth.models)

它会给你所有里面的models东西,在 JavaScript 中有没有类似的东西?

4

3 回答 3

12

你可以使用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"]
于 2013-06-29T14:27:36.780 回答
1

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

于 2013-06-29T14:28:19.453 回答
1

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

console.dir(variable)

ps:这个答案适用于那些在谷歌搜索“javascript中的python dir”(就像我一样!顺便说一句)之后掉到这里的人。

于 2019-04-02T16:08:12.117 回答