473,573 Members | 3,252 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to inspect *all* object properties?

kj

Is there any way to programmaticall y discover and inspect *all*
the properties of an object, even those that are not enumerable
through a for/in loop?

Thanks!

kj

--
NOTE: In my address everything before the period is backwards.
Jul 23 '05 #1
9 12412
kj wrote:
Is there any way to programmaticall y discover and inspect *all*
the properties of an object, even those that are not enumerable
through a for/in loop?


If you can get a list of all possible (or, more realistically, likely)
property names then you can test any object by working through that list
testing to see if the object implements the properties. Non-enumerable
properties will be exposed in that process so long as their names
correspond with an item in the list.

Richard.
Jul 23 '05 #2
I'm not sure about "all", but if you use the MS script editor, you can walk
thru all the DOM objects and collections, inspecting each object for ID,
NAME and PARENT properties.

http://www.mandala.com/javascript/debug_javascript.html

I've written up a page explaining how to use the MS Script Editor for
Javascript debugging in IE. It's a great debugging environment and has
allowed my group to do much more with Javascript in IE with JSP files
than we would have attempted without it. This is NOT THE MS SCRIPT
DEBUGGER but a great editor/debugger included with Office XP/2000.
Very robust, and works great with JSP (and ASP), unlike the usual MS
tools like Visual Studio.

Please pass this around, as I think JSP developers especially need
this tool if they are using IE for development with complex
Javascript.

Of course, if you are using Netscape or Mozilla, Venkman is a good
debugger as well.

Cheers,
Jeff Papineau
San Jose, CA
"Richard Cornford" <Ri*****@litote s.demon.co.uk> wrote in message
news:cc******** ***********@new s.demon.co.uk.. .
kj wrote:
Is there any way to programmaticall y discover and inspect *all*
the properties of an object, even those that are not enumerable
through a for/in loop?


If you can get a list of all possible (or, more realistically, likely)
property names then you can test any object by working through that list
testing to see if the object implements the properties. Non-enumerable
properties will be exposed in that process so long as their names
correspond with an item in the list.

Richard.

Jul 23 '05 #3
You mean properties of a DOM node?
Perhaps you mean properties in general objects, like those in an object
like, say, plugins.

=========
alert(typeof navigator.plugi ns);
for(var i in navigator.plugi ns){alert(i);}
=========
that generates erros in IE, for it is eventually reached _one_property that
refuses to be read. And this though the first alert says "obejct" and thus
it should have been 101% fit to be scanned by a for-in loop.

Yet these and other objects generate errors when scanned via SCRIPT by a
for-in loop. Some properties refuse to be read.
I don't know why, but probably there is either a read-protection device or a
private or protected signature in their prototypse, and if so there is
pretty little you can do to access them.

I hope I understood your question
ciao
Alberto
http://www.unitedscripters.com/
"kj" <so***@987jk.co m> ha scritto nel messaggio
news:cc******** **@reader2.pani x.com...

Is there any way to programmaticall y discover and inspect *all*
the properties of an object, even those that are not enumerable
through a for/in loop?

Thanks!

kj

--
NOTE: In my address everything before the period is backwards.

Jul 23 '05 #4
Richard Cornford wrote:
kj wrote:
Is there any way to programmaticall y discover and inspect *all*
the properties of an object, even those that are not enumerable
through a for/in loop?


If you can get a list of all possible (or, more realistically, likely)
property names then you can test any object by working through that list
testing to see if the object implements the properties. Non-enumerable
properties will be exposed in that process so long as their names
correspond with an item in the list.

Richard.


<tongueinchee k>

Or access the "typeof" every property name with 1 to 16 characters in the
set [a-zA-Z]. In other words:

[object].a, [object].b, ..., [object].aa, [object].ab, ...,
[object].aaaaaaaaaaaaaa aa, [object].aaaaaaaaaaaaaa ab, ...,
[object].zzzzzzzzzzzzzz zz, then all uppercase [A-Z], then mixed [a-zA-Z].

If you set it up to run today, it would probably be done before you slept
the big sleep, but I wouldn't count on it.

I picked 16 character completely arbitrarily, and, as it turns out,
inappropriately , considering the W3C specified document.getEle mentsByTagName
is a method label with 20 characters in it, and even if the code generating
the list above finished in a reasonable period of time, it would have missed
getElementsByTa gName.

You could probably make the code slightly more efficient by retrieving the
list of publically exposed properties and methods using for (... in ...),
then excluding those from the autogenerated list, but I doubt it would save
you much.

</tongueincheek>

As a mental exercise, I decided to waste my time trying this out. Here is a
general purpose function for finding all up to four lowercase letter
properties and methods on any object. Included is a test case for the
"document" object, and a code-snippet to show that the function does,
indeed, list all properties and methods up to four characters in the set
[a-z]:

function allProp(obj, previousProp, depth) {
if (!previousProp) {
previousProp = '';
}
var newProperty, properties = [];
for (var i = 97; i < 123; i++) {
newProperty = previousProp + String.fromChar Code(i);
if (previousProp.l ength < 3) {
properties = properties.conc at(allProp(obj, newProperty));
}
if (typeof obj[newProperty] != 'undefined') {
properties.push (newProperty);
}
}
return properties;
}
var prop = allProp(documen t);

// code to test results
var s = [];
for (var i in prop) {
s.push(i + ' = ' + prop[i] + ' = ' + document[prop[i]]);
}
document.write( s.join('<br>')) ;

Note that while this runs quite snappily in IE, in Firefox 0.9.1, I got
about 6 alerts telling me script was causing the browser to run slowly. I
kept at it until it eventually finished, and discovered, much to my
amazement, that Firefox 0.9.1 supports "document.eval( )".

--
| Grant Wagner <gw*****@agrico reunited.com>

* Client-side Javascript and Netscape 4 DOM Reference available at:
*
http://devedge.netscape.com/library/...ce/frames.html

* Internet Explorer DOM Reference available at:
*
http://msdn.microsoft.com/workshop/a...ence_entry.asp

* Netscape 6/7 DOM Reference available at:
* http://www.mozilla.org/docs/dom/domref/
* Tips for upgrading JavaScript for Netscape 7 / Mozilla
* http://www.mozilla.org/docs/web-deve...upgrade_2.html
Jul 23 '05 #5
Grant Wagner <gw*****@agrico reunited.com> writes:
<tongueinchee k>

Or access the "typeof" every property name with 1 to 16 characters in the
set [a-zA-Z]. In other words: .... If you set it up to run today, it would probably be done before you slept
the big sleep, but I wouldn't count on it.
Nor would I. That's 52^17-2, or 148613013882162 475899836956670 ,
(~148*10^27) different combinations.
If you test one thousand million combinatios every second, it'll take
4699612106676 (~4.7*10^12) years ... more than the projected lifetime
of the univers.

Ofcourse, any unicode letter can be used in a property name, so a-zA-Z
is a very drastic simplification as well.
As a mental exercise, I decided to waste my time trying this out. Here is a
general purpose function for finding all up to four lowercase letter
properties and methods on any object.


52^5-2 = 380204030. Only 380 million combinations. That's doable :)
/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 23 '05 #6
Grant Wagner wrote:
Richard Cornford wrote:
If you can get a list of all possible (or, more realistically,
likely) property names then you can ...
<snip> <tongueinchee k>

Or access the "typeof" every property name with 1 to 16 characters in
the set [a-zA-Z]. In other words:

[object].a, [object].b, ..., [object].aa, [object].ab, ...,
[object].aaaaaaaaaaaaaa aa, [object].aaaaaaaaaaaaaa ab, ...,
[object].zzzzzzzzzzzzzz zz, then all uppercase [A-Z], then mixed
[a-zA-Z].

If you set it up to run today, it would probably be done before you
slept the big sleep, but I wouldn't count on it. <snip> </tongueincheek>
Yes, trying all the possible property names (even just the ones allowed
by any javascript implementation, which probably limits the maximum
length of a property name in a way that the ECMA specification does not)
is not a practical proposition. I wonder whether assuming that property
names will be camel-case combinations of real words would make it
practical to a dictionary and try all the combination permutations of,
say, up to four words. Though I doubt that would help much and there is
no guarantee that non-enumerable property names are even in English so
it would be difficult to chose a dictionary for the task.

On the other hand there isn't an alternative to a list of some sort as
javascript offers no mechanism for exposing non-enumerable properties.
And to some extent the process works. Opera 6 does not list any
properties of its DOM elements with a - for(prop in obj) - loop, yet
trying a list of likely candidates did a fairly good job of exposing the
details of its object model. As listed at:-

<URL: http://www.litotes.demon.co.uk/dom_root.html >

And also exposed the interesting detail that Opera 6's DOM element
property names are mostly not particularly case sensitive (the
consequence of trying out likely case variants).

<snip> Note that while this runs quite snappily in IE, in Firefox 0.9.1, I
got about 6 alerts telling me script was causing the browser to run
slowly.
That is a running problem with my DOM scanning script. Different
browsers have different sensitivities to the duration of running scripts
and the more the process is split up with setTimeout calls the slower it
becomes (though not as slow as having to sit there and dismiss the
warning dialogs by hand).
I kept at it until it eventually finished, and discovered,
much to my amazement, that Firefox 0.9.1 supports "document.eval( )".


Every object in the Gecko DOM has an - eval - method. It may have been
deprecated as a property of objects since JavaScript 1.3 (and never been
part of ECMAScript) but it hasn't actually been removed yet.

Richard.

Jul 23 '05 #7
Gee can anyone say "for (var i in obj){...}
See article by

Danny Goodman
(http://developer.netscape.com/viewso...odman_debug.ht
ml)
Code from Danny:
Listing 1

// Simple browser sniffing needed here
var isNav = (navigator.appN ame == "Netscape")
// Output list of properties for the object
function dumpProps(objNa me) {
var obj = eval(objName)
var msg = ""
var count = 0
var maxProps = 10
// Loop through properties of the object
for (var i in obj) {
if (i != "outerHTML" && i != "outerText" && i != "innerHTML" && i
!= "innerText" && i != "domain") {
msg += objName + "." + i + "=" + obj[i] + "\n"
if (count > maxProps) {
// Output a batch
if (isNav) {
java.lang.Syste m.out.println(m sg)
}
else {
alert(msg)
}
msg = ""
count = 0
continue
}
count++
}
}
// Output any leftovers
if (isNav) {
java.lang.Syste m.out.println(m sg)
} else {
alert(msg)
}
}
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 23 '05 #8
sidney johnson wrote:
Gee can anyone say "for (var i in obj){...}
See article by

<snip>

for(var prop in obj){ ....} - explicitly _does_not_ report
non-enumerable properties of objects (which is what the OP asked to do).

Richard.
Jul 23 '05 #9

oops sorry
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 23 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
2225
by: Robin Becker | last post by:
def raise_an_error(): a = 3 b = 4 c = 0 try: a = a/c except: import sys, cgitb, traceback, inspect tbt,tbv,tb = sys.exc_info() print 'traceback\n',''.join(traceback.format_exception(tbt,tbv,tb))
4
1833
by: Hans Georg Krauthaeuser | last post by:
Dear all, I have a problem to get the command that has called a function if the command was given on multiple lines. E.g.: ################################################### import inspect def call(a,b,c,d,e): s = inspector()
2
1614
by: Fernando Perez | last post by:
Hi all, IPython has suffered quite a few problems with the inspect module in python 2.3. For these, unfortunately all I've been able to do is guard with overreaching except clauses, as I had not been able to find small, reproducible examples to pass on to the devs. But today I got a crash report from a user and I've been able to replicate...
5
1924
by: Tim Henderson | last post by:
Hello I want to creat a program that can inspect a set of classes that i have made and spit out a savable version of these classes. To do this I need to be able to inspect each class and get all of its instance data as well as information about a particular meathod. This is what i want it to do: class song:
5
2084
by: Brian Kitt | last post by:
I have a C# application that builds dynamic HTML and renders it. Because it is rendered in this way, the input controls are not server controls. I write the entire page, which has a variable number of detail lines for an order. I want the user to be able to change values on these detail lines and hit an 'update' button. I know how to do...
0
993
by: castironpi | last post by:
-----the code: class A: b=2 import inspect print inspect.getsource(A) class A: c=2 print inspect.getsource(A)
0
881
by: Stef Mientki | last post by:
hello, I'm not familiar with inspect, but I get an error (see below) in getmembers ( wx ) Of course this is bug in wx . But would you also call this a bug in inspect ?
0
139
by: Terry Reedy | last post by:
Stef Mientki wrote: In my opinion, no. In any case, the doc says "inspect.getmembers(object) Return all the members of an object in a list of (name, value) pairs sorted by name. " so it is behaving according to spec. Getting the name,value pairs
3
1721
by: Rafe | last post by:
Hi, I think I have discovered two bugs with the inspect module and I would like to know if anyone can spot any traps in my workaround. I needed a function which takes a function or method and returns the code inside it (it also adjusts the indent because I have to paste the to a text string without indents, which is parsed later...long...
0
7741
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7661
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7730
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8026
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6347
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5550
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3692
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3686
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2163
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.