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()).

Share:
11,255
Ferdy
Author by

Ferdy

Updated on June 19, 2022

Comments

  • Ferdy
    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
    Ferdy over 12 years
    Thank 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
    Felix Kling over 12 years
    @Frawr: Any reason you use eval? Why not typeof window[x] === 'function' and console.log(window[x])?
  • heinob
    heinob over 9 years
    This does not list XMLHttpRequest. Is there a way to get this also?
  • Niet the Dark Absol
    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
    Lori almost 9 years
    Is there a nodejs version of this little script?