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.

6
  • 4
    What is the point of doing this? How would you use the list? Commented Jan 1, 2012 at 15:57
  • Why / Where you want this ? Please explain something more Commented Jan 1, 2012 at 15:59
  • 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? Commented Jan 1, 2012 at 16:00
  • Built-in where? In the browsers? In the language? Commented Jan 1, 2012 at 16:00
  • Just open the browsers inspector tool and start browsing the hierarchy of objects/methods Commented Jan 1, 2012 at 16:11

3 Answers 3

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

Sign up to request clarification or add additional context in comments.

5 Comments

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
@Frawr: Any reason you use eval? Why not typeof window[x] === 'function' and console.log(window[x])?
This does not list XMLHttpRequest. Is there a way to get this also?
@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.
Is there a nodejs version of this little script?
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

Comments

0

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

console.log(globalThis)

globalThis unites window, self and frames objects.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.