traversing JavaScript namespace

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Plamen Valtchev

    traversing JavaScript namespace

    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="javas cript" 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
  • Martin Honnen

    #2
    Re: traversing JavaScript namespace



    Plamen Valtchev wrote:
    [color=blue]
    > 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="javas cript" 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 ![/color]


    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


    Comment

    • Ira Baxter

      #3
      Re: traversing JavaScript namespace

      "Plamen Valtchev" <plamen@genient .com> wrote in message
      news:8228c0d6.0 402060603.67017 3b6@posting.goo gle.com...
      [color=blue]
      > 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="javas cript" 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 ?[/color]

      You could use a real JavaScript parser that understood HTML to figure
      this out off line. See



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

      Comment

      • Ivo

        #4
        Re: traversing JavaScript namespace

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

        txt = document.script s[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.srcipt s[n].src into a hidden textarea to let the code 'read' the
        code. Less clumsy solutions are welcome!
        HTH
        Ivo
        "Ira Baxter" <idbaxter@semde signs.com> wrote in message
        news:40282e0c$7 @giga.realtime. net...[color=blue]
        > "Plamen Valtchev" <plamen@genient .com> wrote in message
        > news:8228c0d6.0 402060603.67017 3b6@posting.goo gle.com...
        >[color=green]
        > > 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="javas cript" 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 ?[/color]
        >
        > 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[/color]
        News==----[color=blue]
        > http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000[/color]
        Newsgroups[color=blue]
        > ---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption[/color]
        =---


        Comment

        Working...