Trying to get a list of available JavaScript functions/methods

  • Follow


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
0
Reply thegman 5/10/2008 2:14:59 PM

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
0
Reply Thomas 5/10/2008 2:30:11 PM


In comp.lang.javascript message <4825B173.6020508@PointedEars.de>, Sat,
10 May 2008 16:30:11, Thomas 'PointedEars' Lahn <PointedEars@web.de>
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.
0
Reply Dr 5/10/2008 6:48:08 PM

On May 10, 3:30=A0pm, Thomas 'PointedEars' Lahn <PointedE...@web.de>
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. =A0Care 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
0
Reply thegman 5/10/2008 6:50:03 PM

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_usubject=list+functions&as_ugroup=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$8300dec7@news.demon.co.uk>
0
Reply Thomas 5/10/2008 7:27:35 PM

On May 10, 6:14 pm, thegman <taylor.ga...@gmail.com> 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.
0
Reply VK 5/10/2008 8:25:51 PM

On May 10, 9:25=A0pm, VK <schools_r...@yahoo.com> wrote:
> On May 10, 6:14 pm, thegman <taylor.ga...@gmail.com> 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

0
Reply thegman 5/10/2008 9:32:25 PM

> > > 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?

0
Reply VK 5/10/2008 9:52:57 PM

On May 10, 10:52=A0pm, VK <schools_r...@yahoo.com> 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
0
Reply thegman 5/10/2008 11:12:42 PM

> > 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[i] + '=' + probe[arr[i]] + '\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

0
Reply VK 5/11/2008 7:33:35 AM

[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
0
Reply Thomas 5/11/2008 9:13:41 AM

On May 11, 8:33=A0am, VK <schools_r...@yahoo.com> 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
> =A0if (typeof someProperty =3D=3D '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=3D"en-US">
> <head>
> <meta http-equiv=3D"Content-type"
> =A0content=3D"text/html; charset=3Diso-8859-1">
> <title>Demo</title>
> <script type=3D"text/javascript">
> function init() {
> =A0var out =3D document.forms[0].elements['out'];
> =A0var arr =3D new Array;
> =A0var probe =3D window;
> =A0for (var p in probe) {
> =A0 arr.push(''+p);
> =A0}
> =A0arr.sort();
> =A0for (var i=3D0; i<arr.length; i++) {
> =A0 out.value+=3D arr[i] + '=3D' + probe[arr[i]] + '\n\n';
> =A0}}
>
> function releaseContextAndInit() {
> =A0window.setTimeout('init()',10);}
>
> window.onload =3D releaseContextAndInit;
> </script>
> </head>
> <body>
> <form action=3D"" onsubmit=3D"return false;">
> <fieldset>
> =A0<legend>Demo</legend>
> =A0<textarea name=3D"out" rows=3D"16" cols=3D"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=3D"text/javascript" src=3D"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
0
Reply thegman 5/11/2008 11:50:02 AM

On May 11, 12:14=A0am, thegman <taylor.ga...@gmail.com> 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/comp.lang.javascript/browse_frm/thread/785=
8673135763d32/e381a59080b87b5b?hl=3Den&lnk=3Dgst&q=3Dlist+of+functions#e381a=
59080b87b5b
>


--
Rob
0
Reply RobG 5/11/2008 12:31:26 PM

On May 11, 3:50 pm, thegman <taylor.ga...@gmail.com> wrote:
> On May 11, 8:33 am, VK <schools_r...@yahoo.com> 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[i] + '=' + probe[arr[i]] + '\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.


0
Reply VK 5/11/2008 4:10:55 PM

In comp.lang.javascript message <4826B8C5.1050000@PointedEars.de>, Sun,
11 May 2008 11:13:41, Thomas 'PointedEars' Lahn <PointedEars@web.de>
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
0
Reply Dr 5/11/2008 6:45:57 PM

14 Replies
104 Views

(page loaded in 0.134 seconds)

Similiar Articles:


















7/29/2012 8:30:33 PM


Reply: