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?
The dir() function returns all properties and methods of the specified object, without the values. This function will return all the properties and methods, even built-in properties which are default for all object.
Python's "object-based" subset is roughly equivalent to JavaScript. Like JavaScript (and unlike Java), Python supports a programming style that uses simple functions and variables without engaging in class definitions.
dir() The method console. dir() displays an interactive list of the properties of the specified JavaScript object. The output is presented as a hierarchical listing with disclosure triangles that let you see the contents of child objects.
Python dir() function returns the list of names in the current local scope. If the object on which method is called has a method named __dir__(), this method will be called and must return the list of attributes. It takes a single object type argument. The signature of the function is given below.
You 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_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"]
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With