is it possible to loop through all objects?

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

    is it possible to loop through all objects?

    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.
  • Lasse Reichstein Nielsen

    #2
    Re: is it possible to loop through all objects?

    bry@itnisk.com (Bryan) writes:
    [color=blue]
    > 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?[/color]

    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.prototyp e.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 :)
    [color=blue]
    > This is a non-browser environment, specifically the scripting engine
    > for doing xslt extensions in msxml.[/color]

    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 - lrn@hotpop.com
    DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
    'Faith without judgement merely degrades the spirit divine.'

    Comment

    Working...