+ 2
Is there really any equivalent of the python's function dir() in js?
Python's dir() function reveals all the properties of an object and returns a list. This works for both functions and classes(objects). I found out that js has a console.dir() function similar to python's dir(). But this only works for objects. Not for functions.
5 Antworten
+ 3
reversed ( ) you can use Object.getOwnPropertyNames(obj) and
Object.getOwnPropertyNames(obj.prototype)
For example to get all the Array properties
Object.getOwnPropertyNames(Array) or
Object.getOwnPropertyNames(Array.protype)
for Number or String:
Object.getOwnPropertyNames(String.prototype)
Object.getOwnPropertyNames(Number.prototype)
and it works for any function too.
+ 2
Use
Object.keys(obj)
to get all the properties of object obj.
+ 2
Thanks Calviղ for the help! 😄
+ 1
Calviղ does it work for Number or String or any other function?
0
help()