Trying to get a list of available JavaScript functions/methods

Discussion in 'Javascript' started by thegman, May 10, 2008.

  1. thegman

    thegman Guest

    Hi all,
    I'm trying to get list of JavaScript methods/functions in a script
    file in much the same a good text editor will, the difference being
    that I need to output it to a file or stdout, or some other way of
    "getting at it" automatically. I'm not fussy about what language I
    use, be it JavaScript or something else. Anyone got any ideas? I've
    tried Exuberant Ctags, but that does not seem to work on very advanced
    scripts like Ext.

    I'm guessing the best way would be to have some kind of interrogation
    of a HTMLScriptElement or something, but I can't see how to get a
    simple list of functions/methods from that.

    Alternatively, any C library for parsing JS might be a good idea, even
    Python, Perl, PHP, whatever really, anyone got any recommendations?

    Cheers

    Garry
    thegman, May 10, 2008
    #1
    1. Advertising

  2. thegman wrote:
    > I'm trying to get list of JavaScript methods/functions in a script
    > file in much the same a good text editor will, the difference being
    > that I need to output it to a file or stdout, or some other way of
    > "getting at it" automatically.


    You are about the 1337th person to ask that question here. Care to do
    a *little* research before you bother other people with your problems?

    http://jibbering.com/faq/


    PointedEars
    --
    Anyone who slaps a 'this page is best viewed with Browser X' label on
    a Web page appears to be yearning for the bad old days, before the Web,
    when you had very little chance of reading a document written on another
    computer, another word processor, or another network. -- Tim Berners-Lee
    Thomas 'PointedEars' Lahn, May 10, 2008
    #2
    1. Advertising

  3. In comp.lang.javascript message <>, Sat,
    10 May 2008 16:30:11, Thomas 'PointedEars' Lahn <>
    posted:
    >thegman wrote:
    >> I'm trying to get list of JavaScript methods/functions in a script
    >> file in much the same a good text editor will, the difference being
    >> that I need to output it to a file or stdout, or some other way of
    >> "getting at it" automatically.

    >
    >You are about the 1337th person to ask that question here. Care to do
    >a *little* research before you bother other people with your problems?
    >
    >http://jibbering.com/faq/


    If you had intended to be helpful, you would have given the number of
    the relevant section. There is no section which, to the intended
    audience, will appear helpful. The OP will realise that, whatever your
    intent, your main effect when replying to newcomers is to demonstrate
    how obnoxious you are.

    --
    (c) John Stockton, nr London UK. ???@merlyn.demon.co.uk Turnpike v6.05 MIME.
    Web <URL:http://www.merlyn.demon.co.uk/> - FAQish topics, acronyms, & links.
    Check boilerplate spelling -- error is a public sign of incompetence.
    Never fully trust an article from a poster who gives no full real name.
    Dr J R Stockton, May 10, 2008
    #3
  4. thegman

    thegman Guest

    On May 10, 3:30 pm, Thomas 'PointedEars' Lahn <>
    wrote:
    > thegman wrote:
    > > I'm trying to get list of JavaScript methods/functions in a script
    > > file in much the same a good text editor will, the difference being
    > > that I need to output it to a file or stdout, or some other way of
    > > "getting at it" automatically.

    >
    > You are about the 1337th person to ask that question here.  Care to do
    > a *little* research before you bother other people with your problems?
    >
    > http://jibbering.com/faq/
    >
    > PointedEars
    > --
    > Anyone who slaps a 'this page is best viewed with Browser X' label on
    > a Web page appears to be yearning for the bad old days, before the Web,
    > when you had very little chance of reading a document written on another
    > computer, another word processor, or another network. -- Tim Berners-Lee



    I've looked around quite a lot, maybe I'm the worst Googler in the
    world or something, but I can't find what I'm looking for, if
    someone's got some links, I'd appreciate it.

    Thanks

    Garry
    thegman, May 10, 2008
    #4
  5. thegman wrote:
    > [...] Thomas 'PointedEars' Lahn [...] wrote:
    >> thegman wrote:
    >>> I'm trying to get list of JavaScript methods/functions in a script
    >>> file in much the same a good text editor will, the difference being
    >>> that I need to output it to a file or stdout, or some other way of
    >>> "getting at it" automatically.

    >> You are about the 1337th person to ask that question here. Care to do
    >> a *little* research before you bother other people with your problems?
    >>
    >> http://jibbering.com/faq/
    >> [...]


    Please trim your quotes as also recommended by the FAQ Notes.

    > I've looked around quite a lot, maybe I'm the worst Googler in the
    > world or something, but I can't find what I'm looking for, if
    > someone's got some links, I'd appreciate it.


    http://groups.google.com/groups?as_...group=comp.lang.javascript&scoring=d&filter=0


    PointedEars
    --
    Prototype.js was written by people who don't know javascript for people
    who don't know javascript. People who don't know javascript are not
    the best source of advice on designing systems that use javascript.
    -- Richard Cornford, cljs, <f806at$ail$1$>
    Thomas 'PointedEars' Lahn, May 10, 2008
    #5
  6. thegman

    VK Guest

    On May 10, 6:14 pm, thegman <> wrote:

    > I'm trying to get list of JavaScript methods/functions in a script


    1) Top level functions only or all functions together, including
    anonymous and nested ones? The latter one is pretty much impossible w/
    o operating on a lower level via XPCOM/C (Gecko) or C++ (IE) - just to
    let you know in advance.

    2) Custom functions only or everything? Say setTimeout should be in
    your list or now?

    3) For the running script or for the script source treated as plain
    text?

    With these questions answered the rest should be rather easy.
    VK, May 10, 2008
    #6
  7. thegman

    thegman Guest

    On May 10, 9:25 pm, VK <> wrote:
    > On May 10, 6:14 pm, thegman <> wrote:
    >
    > > I'm trying to get list of JavaScript methods/functions in a script

    >
    > 1) Top level functions only or all functions together, including
    > anonymous and nested ones? The latter one is pretty much impossible w/
    > o operating on a lower level via XPCOM/C (Gecko) or C++ (IE) - just to
    > let you know in advance.


    All functions, but particularly functions/methods defined in third-
    party scripts such as Ext.

    >
    > 2) Custom functions only or everything? Say setTimeout should be in
    > your list or now?


    Would be good to have setTimeout and other builtins, but not
    essential.

    >
    > 3) For the running script or for the script source treated as plain
    > text?


    Not fussy, I don't mind doing this with JavaScript, or pretty much any
    other language.

    >
    > With these questions answered the rest should be rather easy.


    Thanks for the reply, I've been looking at this most of the day, and
    not come up with any bulletproof solutions yet.

    Cheers!

    Garry
    thegman, May 10, 2008
    #7
  8. thegman

    VK Guest

    > > > I'm trying to get list of JavaScript methods/functions in a script
    >
    > > 1) Top level functions only or all functions together, including
    > > anonymous and nested ones? The latter one is pretty much
    > > impossible w/o operating on a lower level via XPCOM/C (Gecko) or
    > > C++ (IE) - just to let you know in advance.

    >
    > All functions, but particularly functions/methods defined in third-
    > party scripts such as Ext.


    What is your level of programming experience? In the particular how
    would you define "all anonymous functions"? All named references to a
    function or the initial reference only? If you don't understand the
    question I can try to rephrase it with a sample.

    > > 2) Custom functions only or everything? Say setTimeout should be
    > > in your list or not?

    >
    > Would be good to have setTimeout and other builtins, but not
    > essential.


    'k


    > > 3) For the running script or for the script source treated
    > > as plain text?


    > Not fussy, I don't mind doing this with JavaScript,
    > or pretty much any other language.


    You didn't understand me. My question was: do you want to study a
    running code for method references - or you want to parse some text
    say library.js to find all occurrences of "function" string in it and
    regexp with it?
    VK, May 10, 2008
    #8
  9. thegman

    thegman Guest

    On May 10, 10:52 pm, VK <> wrote:
    > > > > I'm trying to get list of JavaScript methods/functions in a script

    >
    > > > 1) Top level functions only or all functions together, including
    > > > anonymous and nested ones? The latter one is pretty much
    > > > impossible w/o operating on a lower level via XPCOM/C (Gecko) or
    > > > C++ (IE) - just to let you know in advance.

    >
    > > All functions, but particularly functions/methods defined in third-
    > > party scripts such as Ext.

    >
    > What is your level of programming experience? In the particular how
    > would you define "all anonymous functions"? All named references to a
    > function or the initial reference only? If you don't understand the
    > question I can try to rephrase it with a sample.


    My programming experience is longer than I care to remember, but not
    JS, not even slightly, which is probably not helping my cause much. I
    guess any function/method which is usable, I'd like to list that.


    >
    > You didn't understand me. My question was: do you want to study a
    > running code for method references - or you want to parse some text
    > say library.js to find all occurrences of "function" string in it and
    > regexp with it?


    I understand your question, it's just that I'm not bothered which way
    I end up doing this, I can use JavaScript in a running browser, and
    capture the output, or indeed run some kind of regex thing and get the
    results that way, I'm relatively indifferent about how I get this
    done, just so long as it works. My first thought was to use something
    like ctags, or maybe a Python parser, but I could not find anything
    which was much good. My thoughts then turned to using the DOM tree or
    something like that, which I'd expect to be a bit more robust, after
    all, what understand JS better than a browser?

    Thanks

    Garry
    thegman, May 11, 2008
    #9
  10. thegman

    VK Guest

    > > What is your level of programming experience? In the particular how
    > > would you define "all anonymous functions"? All named references to a
    > > function or the initial reference only? If you don't understand the
    > > question I can try to rephrase it with a sample.


    > My programming experience is longer than I care to remember, but not
    > JS, not even slightly, which is probably not helping my cause much. I
    > guess any function/method which is usable, I'd like to list that.


    You may start with a simple for-in loop to get your feet wet in
    Javascript.
    Also
    if (typeof someProperty == 'object')
    will tell you if someProperty is an object by itself with its own
    possible set of properties to go on recursion. Ask if you need more
    help.

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
    <html lang="en-US">
    <head>
    <meta http-equiv="Content-type"
    content="text/html; charset=iso-8859-1">
    <title>Demo</title>
    <script type="text/javascript">
    function init() {
    var out = document.forms[0].elements['out'];
    var arr = new Array;
    var probe = window;
    for (var p in probe) {
    arr.push(''+p);
    }
    arr.sort();
    for (var i=0; i<arr.length; i++) {
    out.value+= arr + '=' + probe[arr] + '\n\n';
    }
    }
    function releaseContextAndInit() {
    window.setTimeout('init()',10);
    }
    window.onload = releaseContextAndInit;
    </script>
    </head>
    <body>
    <form action="" onsubmit="return false;">
    <fieldset>
    <legend>Demo</legend>
    <textarea name="out" rows="16" cols="64"></textarea>
    </fieldset>
    </form>
    </body>
    </html>



    > > You didn't understand me. My question was: do you want to study a
    > > running code for method references - or you want to parse some text
    > > say library.js to find all occurrences of "function" string in it and
    > > regexp with it?

    >
    > I understand your question, it's just that I'm not bothered which way
    > I end up doing this, I can use JavaScript in a running browser, and
    > capture the output, or indeed run some kind of regex thing and get the
    > results that way, I'm relatively indifferent about how I get this
    > done, just so long as it works. My first thought was to use something
    > like ctags, or maybe a Python parser, but I could not find anything
    > which was much good. My thoughts then turned to using the DOM tree or
    > something like that, which I'd expect to be a bit more robust, after
    > all, what understand JS better than a browser?
    >
    > Thanks
    >
    > Garry
    VK, May 11, 2008
    #10
  11. [snipped attribution novel]

    Dr J R Stockton wrote:
    > Thomas 'PointedEars' Lahn posted:
    >> thegman wrote:
    >>> I'm trying to get list of JavaScript methods/functions in a script
    >>> file in much the same a good text editor will, the difference being
    >>> that I need to output it to a file or stdout, or some other way of
    >>> "getting at it" automatically.

    >> You are about the 1337th person to ask that question here. Care to do
    >> a *little* research before you bother other people with your problems?
    >>
    >> http://jibbering.com/faq/

    >
    > If you had intended to be helpful, you would have given the number of
    > the relevant section. There is no section which, to the intended
    > audience, will appear helpful. [snipped flame]


    The relevant section is the one describing where the newsgroup's archives are.


    PointedEars
    --
    Anyone who slaps a 'this page is best viewed with Browser X' label on
    a Web page appears to be yearning for the bad old days, before the Web,
    when you had very little chance of reading a document written on another
    computer, another word processor, or another network. -- Tim Berners-Lee
    Thomas 'PointedEars' Lahn, May 11, 2008
    #11
  12. thegman

    thegman Guest

    On May 11, 8:33 am, VK <> wrote:
    > > > What is your level of programming experience? In the particular how
    > > > would you define "all anonymous functions"? All named references to a
    > > > function or the initial reference only? If you don't understand the
    > > > question I can try to rephrase it with a sample.

    > > My programming experience is longer than I care to remember, but not
    > > JS, not even slightly, which is probably not helping my cause much. I
    > > guess any function/method which is usable, I'd like to list that.

    >
    > You may start with a simple for-in loop to get your feet wet in
    > Javascript.
    > Also
    >  if (typeof someProperty == 'object')
    > will tell you if someProperty is an object by itself with its own
    > possible set of properties to go on recursion. Ask if you need more
    > help.
    >
    > <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
    > <html lang="en-US">
    > <head>
    > <meta http-equiv="Content-type"
    >  content="text/html; charset=iso-8859-1">
    > <title>Demo</title>
    > <script type="text/javascript">
    > function init() {
    >  var out = document.forms[0].elements['out'];
    >  var arr = new Array;
    >  var probe = window;
    >  for (var p in probe) {
    >   arr.push(''+p);
    >  }
    >  arr.sort();
    >  for (var i=0; i<arr.length; i++) {
    >   out.value+= arr + '=' + probe[arr] + '\n\n';
    >  }}
    >
    > function releaseContextAndInit() {
    >  window.setTimeout('init()',10);}
    >
    > window.onload = releaseContextAndInit;
    > </script>
    > </head>
    > <body>
    > <form action="" onsubmit="return false;">
    > <fieldset>
    >  <legend>Demo</legend>
    >  <textarea name="out" rows="16" cols="64"></textarea>
    > </fieldset>
    > </form>
    > </body>
    > </html>
    >
    > > > You didn't understand me. My question was: do you want to study a
    > > > running code for method references - or you want to parse some text
    > > > say library.js to find all occurrences of "function" string in it and
    > > > regexp with it?

    >
    > > I understand your question, it's just that I'm not bothered which way
    > > I end up doing this, I can use JavaScript in a running browser, and
    > > capture the output, or indeed run some kind of regex thing and get the
    > > results that way, I'm relatively indifferent about how I get this
    > > done, just so long as it works. My first thought was to use something
    > > like ctags, or maybe a Python parser, but I could not find anything
    > > which was much good. My thoughts then turned to using the DOM tree or
    > > something like that, which I'd expect to be a bit more robust, after
    > > all, what understand JS better than a browser?

    >
    > > Thanks

    >
    > > Garry


    VK, thank you, you have been very helpful, just one more question, and
    I'll leave you alone, to your script (which is very enlightening BTW),
    I added a counter, just to see how many objects it lists, the result
    was 244, I added this line:

    <script type="text/javascript" src="ext-2.1/ext-all.js"></script>


    To the head, and it's still 244, which to me would imply that there
    are no objects present in the script (when I know there are), or would
    I expect to find those objects deeper down the tree? If I need to
    recurse down it, I'm sure I'll work that out, just wondering if I'm on
    the right path.

    Thanks

    Garry
    thegman, May 11, 2008
    #12
  13. thegman

    RobG Guest

    On May 11, 12:14 am, thegman <> wrote:
    > Hi all,
    > I'm trying to get list of JavaScript methods/functions in a script
    > file in much the same a good text editor will, the difference being
    > that I need to output it to a file or stdout, or some other way of
    > "getting at it" automatically. I'm not fussy about what language I
    > use, be it JavaScript or something else. Anyone got any ideas? I've
    > tried Exuberant Ctags, but that does not seem to work on very advanced
    > scripts like Ext.
    >
    > I'm guessing the best way would be to have some kind of interrogation
    > of a HTMLScriptElement or something, but I can't see how to get a
    > simple list of functions/methods from that.
    >
    > Alternatively, any C library for parsing JS might be a good idea, even
    > Python, Perl, PHP, whatever really, anyone got any recommendations?


    This thread may help:

    <URL:
    http://groups.google.com.au/group/c...&lnk=gst&q=list of functions#e381a59080b87b5b
    >



    --
    Rob
    RobG, May 11, 2008
    #13
  14. thegman

    VK Guest

    On May 11, 3:50 pm, thegman <> wrote:
    > On May 11, 8:33 am, VK <> wrote:
    >
    >
    >
    > > > > What is your level of programming experience? In the particular how
    > > > > would you define "all anonymous functions"? All named references to a
    > > > > function or the initial reference only? If you don't understand the
    > > > > question I can try to rephrase it with a sample.
    > > > My programming experience is longer than I care to remember, but not
    > > > JS, not even slightly, which is probably not helping my cause much. I
    > > > guess any function/method which is usable, I'd like to list that.

    >
    > > You may start with a simple for-in loop to get your feet wet in
    > > Javascript.
    > > Also
    > > if (typeof someProperty == 'object')
    > > will tell you if someProperty is an object by itself with its own
    > > possible set of properties to go on recursion. Ask if you need more
    > > help.

    >
    > > <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
    > > <html lang="en-US">
    > > <head>
    > > <meta http-equiv="Content-type"
    > > content="text/html; charset=iso-8859-1">
    > > <title>Demo</title>
    > > <script type="text/javascript">
    > > function init() {
    > > var out = document.forms[0].elements['out'];
    > > var arr = new Array;
    > > var probe = window;
    > > for (var p in probe) {
    > > arr.push(''+p);
    > > }
    > > arr.sort();
    > > for (var i=0; i<arr.length; i++) {
    > > out.value+= arr + '=' + probe[arr] + '\n\n';
    > > }}

    >
    > > function releaseContextAndInit() {
    > > window.setTimeout('init()',10);}

    >
    > > window.onload = releaseContextAndInit;
    > > </script>
    > > </head>
    > > <body>
    > > <form action="" onsubmit="return false;">
    > > <fieldset>
    > > <legend>Demo</legend>
    > > <textarea name="out" rows="16" cols="64"></textarea>
    > > </fieldset>
    > > </form>
    > > </body>
    > > </html>

    >
    > > > > You didn't understand me. My question was: do you want to study a
    > > > > running code for method references - or you want to parse some text
    > > > > say library.js to find all occurrences of "function" string in it and
    > > > > regexp with it?

    >
    > > > I understand your question, it's just that I'm not bothered which way
    > > > I end up doing this, I can use JavaScript in a running browser, and
    > > > capture the output, or indeed run some kind of regex thing and get the
    > > > results that way, I'm relatively indifferent about how I get this
    > > > done, just so long as it works. My first thought was to use something
    > > > like ctags, or maybe a Python parser, but I could not find anything
    > > > which was much good. My thoughts then turned to using the DOM tree or
    > > > something like that, which I'd expect to be a bit more robust, after
    > > > all, what understand JS better than a browser?

    >
    > > > Thanks

    >
    > > > Garry

    >
    > VK, thank you, you have been very helpful, just one more question, and
    > I'll leave you alone, to your script (which is very enlightening BTW),
    > I added a counter, just to see how many objects it lists, the result
    > was 244, I added this line:
    >
    > <script type="text/javascript" src="ext-2.1/ext-all.js"></script>
    >
    > To the head, and it's still 244, which to me would imply that there
    > are no objects present in the script (when I know there are), or would
    > I expect to find those objects deeper down the tree?


    It is hard to guess as I don't know the Ext library. Most probably -
    but only probably - it implements "shy namespace" so instead of top
    level function glbExt (or whatever) it is something like:

    (function() {
    if (typeof glbExt == 'undefined') {
    glbExt = theLibraryBody;
    }
    else {
    // namespace collision workaround
    }
    })();

    In this case you're getting glbExt variable with is not considered as
    a host window property - at least not by IE.

    You need to look at the library structure.
    VK, May 11, 2008
    #14
  15. In comp.lang.javascript message <>, Sun,
    11 May 2008 11:13:41, Thomas 'PointedEars' Lahn <>
    posted:
    >[snipped attribution novel]
    >
    >Dr J R Stockton wrote:
    >> Thomas 'PointedEars' Lahn posted:
    >>> thegman wrote:
    >>>> I'm trying to get list of JavaScript methods/functions in a script
    >>>> file in much the same a good text editor will, the difference being
    >>>> that I need to output it to a file or stdout, or some other way of
    >>>> "getting at it" automatically.
    >>> You are about the 1337th person to ask that question here. Care to do
    >>> a *little* research before you bother other people with your problems?
    >>>
    >>> http://jibbering.com/faq/

    >>
    >> If you had intended to be helpful, you would have given the number of
    >> the relevant section. There is no section which, to the intended
    >> audience, will appear helpful. [snipped flame]


    I did not write all of that. Don't quote misleadingly. Still, it's
    nice to know that you do see that you are considered to be like. Once
    you start to believe that (you are a slow learner), progress might be
    made.

    >The relevant section is the one describing where the newsgroup's archives are.


    OP (thegman) : did you realise that? Do you consider it helpful?

    --
    (c) John Stockton, nr London UK. ?@merlyn.demon.co.uk BP7, Delphi 3 & 2006.
    <URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/&c., FAQqy topics & links;
    <URL:http://www.bancoems.com/CompLangPascalDelphiMisc-MiniFAQ.htm> clpdmFAQ;
    <URL:http://www.borland.com/newsgroups/guide.html> news:borland.* Guidelines
    Dr J R Stockton, May 11, 2008
    #15
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sam
    Replies:
    3
    Views:
    11,259
  2. Xiangliang Meng
    Replies:
    1
    Views:
    1,568
    Victor Bazarov
    Jun 21, 2004
  3. dspfun
    Replies:
    2
    Views:
    839
    Flash Gordon
    Aug 14, 2006
  4. DG
    Replies:
    3
    Views:
    317
    Terry Reedy
    Jul 22, 2009
  5. Kenneth McDonald
    Replies:
    5
    Views:
    288
    Kenneth McDonald
    Sep 26, 2008
Loading...

Share This Page