Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find JavaScript functions in a JavaScript (.js) file?

Tags:

javascript

I need to find or list out all the JavaScript methods in a .js file.

like image 735
Sainath437 Avatar asked Jan 27 '26 06:01

Sainath437


1 Answers

You can programmatically get a list of all the user-defined global functions as follows:

var listOfFunctions = [];

for (var x in window) {

  if (window.hasOwnProperty(x) && 
      typeof window[x] === 'function' &&
      window[x].toString().indexOf('[native code]') > 0) {

    listOfFunctions.push(x);
  }
}

The listOfFunctions array will contain the names of all the global functions which are not native.


UPDATE: As @CMS pointed out in the comments below, the above won't work in Internet Explorer 8 and earlier for global function declarations.

like image 118
Daniel Vassallo Avatar answered Jan 29 '26 20:01

Daniel Vassallo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!