What I loved about Python was that if you wanted to know something about a particular module, you could just go something like this:
dir(django.auth.models)
and it would give you all the things inside of models
, is there something similar to this in JavaScript?
What I loved about Python was that if you wanted to know something about a particular module, you could just go something like this:
dir(django.auth.models)
and it would give you all the things inside of models
, is there something similar to this in JavaScript?
- 4 Here you go: stackoverflow./questions/5523747/… – Joel Kinzel Commented Jun 29, 2013 at 14:28
3 Answers
Reset to default 12You could use Object.keys()
, e.g.:
> Object.keys(window)
["top", "window", "location", "external", "chrome", "Intl", "v8Intl", "document", "$", "jQuery", "MSIsPlayback", "i", "prepareEditor", "StackExchange", "scriptSrc", "careers_adurl", "careers_cssurl", "careers_leaderboardcssurl", "careers_panycssurl", "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"]
I don´t know if doesn´t have this option in 2013, but today we have:
console.dir(variable)
ps: This answer is for those fall here after a googling 'python dir in javascript' (like me! by the way).
If you do console.log(variable)
in javascript, you'll see information about that variable in your browser's debugging console. If the variable is an object for example, you'll see it's attributes.