I need to find or list out all the JavaScript methods in a .js file.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With