List all built-in functions in javascript?
11,255
Something like this, maybe?
for( var x in window) {
if( window[x] instanceof Function) console.log(x);
}
This will list all native functions in the console (excluding one in native objects, such as Math.sin()
).
Author by
Ferdy
Updated on June 19, 2022Comments
-
Ferdy almost 2 years
Is there a way in js to list all the builtin functions and some info on their parameterlists? I couldn't really find anything about reflection to do this sort of thing
edit: The functions such as Math.sin are actually the ones I want to list, actually all built-in functions.
-
Ferdy over 12 yearsThank you, this brings me a little closer, I've changed it to this: for(var x in window) { if(typeof eval('window.' + x) == 'function') { console.log(eval('window.' + x)); } } However, functions such as Math.sin etc are exactly the ones I want to list
-
Felix Kling over 12 years@Frawr: Any reason you use
eval
? Why nottypeof window[x] === 'function'
andconsole.log(window[x])
? -
heinob over 9 yearsThis does not list
XMLHttpRequest
. Is there a way to get this also? -
Niet the Dark Absol over 9 years@heinob Not really. A lot of things will be made non-Enumerable, so they won't show up in a loop like this. This might even be done on purpose with all native stuff, so that a
for..in
could be "useful" as in "iterate through all user-defined global variables" - ideally, this would be empty. -
Lori almost 9 yearsIs there a nodejs version of this little script?