tags:

views:

67

answers:

4

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
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
+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
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
@CMS: Thanks for the note on IE, that's interesting :) ...
Daniel Vassallo
@Daniel, you're welcome. That's IMO one of the worst bugs on IE. Fortunately it's already fixed on IE9. :)
CMS
@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