is it possible to loop through all objects?

Discussion in 'Javascript' started by Bryan, Feb 21, 2004.

  1. Bryan

    Bryan Guest

    If you have a javascript interpreter running in an environment unknown
    to you (as in what objects it exposes to the language) is it possible
    to loop through all objects in some way?

    This is a non-browser environment, specifically the scripting engine
    for doing xslt extensions in msxml.
    Bryan, Feb 21, 2004
    #1
    1. Advertising

  2. (Bryan) writes:

    > If you have a javascript interpreter running in an environment unknown
    > to you (as in what objects it exposes to the language) is it possible
    > to loop through all objects in some way?


    Only by brute-force exhaustive search. I.e., no.

    Javascript allows you to find only some of the properties of objects,
    those that are enumerable. You find them using
    for (var propName in object) { ... }
    Those that are not enumerable cannot be seen except by knowing their
    name. One example is Object.prototype.toString. You know it is there,
    but if you didn't know its name, you wouldn't be able to find it except
    by trying all strings as property names and see if they exist. Since
    there are infintly many strings, that won't work. Restricting to only those
    of, say, 32 letters or below, will make it a finite problem. Sadly,
    the universe is probably also final, and could end before you finish :)

    > This is a non-browser environment, specifically the scripting engine
    > for doing xslt extensions in msxml.


    That depends on that specific environment. If none of the properties it
    adds are non-enumerable, then you can find them. Otherwise, you can't.

    /L
    --
    Lasse Reichstein Nielsen -
    DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
    'Faith without judgement merely degrades the spirit divine.'
    Lasse Reichstein Nielsen, Feb 21, 2004
    #2
    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. Vik

    Loop through all dataadapters

    Vik, Jul 16, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    335
  2. David A. Beck
    Replies:
    4
    Views:
    8,347
    Saravana [MVP]
    Nov 18, 2003
  3. Christina N
    Replies:
    7
    Views:
    806
    Girish Bharadwaj
    Sep 14, 2004
  4. Roedy Green
    Replies:
    3
    Views:
    406
    Mike Schilling
    Sep 13, 2008
  5. Isaac Won
    Replies:
    9
    Views:
    342
    Ulrich Eckhardt
    Mar 4, 2013
Loading...

Share This Page