List all built-in functions in javascript?
Asked Answered
B

3

9

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.

Barton answered 1/1, 2012 at 15:54 Comment(6)
What is the point of doing this? How would you use the list?Patronize
Why / Where you want this ? Please explain something moreSumter
What do you mean by built-in functions? Functions defined in the specification for the global object? Methods of built-in objects (defined by the specification)? Functions of host objects common to browsers? Functions of the DOM?Cahoot
Built-in where? In the browsers? In the language?Chenoweth
Just open the browsers inspector tool and start browsing the hierarchy of objects/methodsInterlace
They are for use in a lisp project. And all functions is as they are specified in the standard, global object, object object, function object etc.Barton
L
10

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

Louella answered 1/1, 2012 at 15:56 Comment(5)
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 listBarton
@Frawr: Any reason you use eval? Why not typeof window[x] === 'function' and console.log(window[x])?Cahoot
This does not list XMLHttpRequest. Is there a way to get this also?Arnold
@Arnold 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.Louella
Is there a nodejs version of this little script?Diffractometer
A
1

Just do console.log(window). Now open your browser and go to console. You will find all the built-in functions of the Javascript like Math.sin and XMLHttpReuest. It will show the complete information about arguments, length, caller and everything about that function.enter image description here

Auberta answered 13/5, 2021 at 9:39 Comment(0)
A
0

Another good way to list all functions (and objects) is:

console.log(globalThis)

globalThis unites window, self and frames objects.

Algid answered 1/5, 2024 at 17:45 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.