HI... I need to find or list out all the JavaScript methods in .js file . pls help me out
A:
In Notepad++ there is a plugin named Function List - you might find it useful.
Dror
2010-10-04 07:19:42
A:
You would have to write a parser in order to understand all the grammar. You might be able to use an existing parser.
meder
2010-10-04 07:24:07
+2
A:
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.
Daniel Vassallo
2010-10-04 07:25:37
You'll get a [surprise](http://blogs.msdn.com/b/ericlippert/archive/2005/05/04/414684.aspx) when you try this on IE<=8. IE can't enumerate identifiers from Function Declarations in the global scope :(
CMS
2010-10-04 07:32:07
@CMS: Thanks for the note on IE, that's interesting :) ...
Daniel Vassallo
2010-10-04 07:37:49
@Daniel, you're welcome. That's IMO one of the worst bugs on IE. Fortunately it's already fixed on IE9. :)
CMS
2010-10-04 07:41:55
@CMS: Yes I agree that it's an awful bug, but does it have practical importance? ... ie. Is iteration over global function declarations useful in browser scripting (in general)?
Daniel Vassallo
2010-10-04 07:45:21
+1
A:
same question as http://stackoverflow.com/questions/493833/list-of-global-user-defined-functions-in-javascript?
jebberwocky
2010-10-04 07:27:02