Trying to get a list of available JavaScript functions/methods

T

thegman

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
 
T

Thomas 'PointedEars' Lahn

thegman said:
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
 
D

Dr J R Stockton

In comp.lang.javascript message <[email protected]>, Sat,
10 May 2008 16:30:11 said:
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.
 
T

thegman

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
 
T

Thomas 'PointedEars' Lahn

thegman said:
thegman said:
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
 
V

VK

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.
 
T

thegman

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
 
V

VK

I'm trying to get list of JavaScript methods/functions in a script
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.
Would be good to have setTimeout and other builtins, but not
essential.
'k
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?
 
T

thegman

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
 
V

VK

What is your level of programming experience? In the particular how
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>
 
T

Thomas 'PointedEars' Lahn

[snipped attribution novel]
Thomas 'PointedEars' Lahn posted:
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
 
T

thegman

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

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
 
R

RobG

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
 
V

VK

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>

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.
 
D

Dr J R Stockton

In comp.lang.javascript message <[email protected]>, Sun,
11 May 2008 11:13:41 said:
[snipped attribution novel]
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?
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,992
Messages
2,570,220
Members
46,807
Latest member
ryef

Latest Threads

Top