Reputation: 11
Is there any specific way for me to capture functions that have been defined in a Javascript file? It is for testing purposes for me to choose functions I want to perform tests in the Javascript file.
Thanking you in advance
Upvotes: 0
Views: 753
Reputation: 4358
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.
The above won't work in Internet Explorer 8 and earlier for global function declarations.
Upvotes: 1