By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,528 Members | 1,338 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,528 IT Pros & Developers. It's quick & easy.

traversing JavaScript namespace

P: n/a
This is my problem:

From JavaScript I want to find the list of all defined/loaded
JavaScript functions/objects/names within the current scope (html page
in a browser).

the page could contain many included javascript with the script tag :

<script language="javascript" src="XXX/Script.js"></script>
and I wont to know the functions that have been loaded from the
included script

I couldn find any way of traversing the JavaScript namespace atall !

any ideas ?

Thanks

Plamen
Jul 20 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a


Plamen Valtchev wrote:
This is my problem:

From JavaScript I want to find the list of all defined/loaded
JavaScript functions/objects/names within the current scope (html page
in a browser).

the page could contain many included javascript with the script tag :

<script language="javascript" src="XXX/Script.js"></script>
and I wont to know the functions that have been loaded from the
included script

I couldn find any way of traversing the JavaScript namespace atall !

Properties marked as enumerable can be enumerated with
for (var prop in object)
The global object in client side JavaScript is the window object so you
can try
var text = '';
for (var prop in window) {
text += prop + ': ' + window[prop] + '| ';
}
alert(text);
however you will find browser dependant differences as to the properties
that are enumerated.

--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 20 '05 #2

P: n/a
"Plamen Valtchev" <pl****@genient.com> wrote in message
news:82**************************@posting.google.c om...
From JavaScript I want to find the list of all defined/loaded
JavaScript functions/objects/names within the current scope (html page
in a browser).

the page could contain many included javascript with the script tag :

<script language="javascript" src="XXX/Script.js"></script>

and I wont to know the functions that have been loaded from the
included script
I couldn find any way of traversing the JavaScript namespace atall !

any ideas ?


You could use a real JavaScript parser that understood HTML to figure
this out off line. See
http://www.semdesigns.com/Products/F...tFrontEnd.html
--
Ira D. Baxter, Ph.D., CTO 512-250-1018
Semantic Designs, Inc. www.semdesigns.com


----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
Jul 20 '05 #3

P: n/a
Ivo
It 's an interesting idea, using javascript to analyse javascript. The
actual scripts on a page are stored in the DOM under "document.scripts",
with "text" and "src" as the most useful branches.
If it is an inline script, you can break up document.scripts[n].text with a
regular expression:

txt = document.scripts[0].text; // first script tag on the page
reg = /function\s*?(\w+)\s*?\(([,\w\s]*?)\)/gm; // searches function names
if( list = txt.match(reg) )
alert( list.join('\n') );
else
alert( 'No functions in this script!' );

External scripts are a bit more difficult. I have found myself loading
document.srcipts[n].src into a hidden textarea to let the code 'read' the
code. Less clumsy solutions are welcome!
HTH
Ivo
"Ira Baxter" <id******@semdesigns.com> wrote in message
news:40********@giga.realtime.net...
"Plamen Valtchev" <pl****@genient.com> wrote in message
news:82**************************@posting.google.c om...
From JavaScript I want to find the list of all defined/loaded
JavaScript functions/objects/names within the current scope (html page
in a browser).

the page could contain many included javascript with the script tag :

<script language="javascript" src="XXX/Script.js"></script>

and I wont to know the functions that have been loaded from the
included script
I couldn find any way of traversing the JavaScript namespace atall !

any ideas ?
You could use a real JavaScript parser that understood HTML to figure
this out off line. See
http://www.semdesigns.com/Products/F...tFrontEnd.html
--
Ira D. Baxter, Ph.D., CTO 512-250-1018
Semantic Designs, Inc. www.semdesigns.com


----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet

News==---- http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups ---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption

=---
Jul 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.