Richard said:
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.
<tongueincheek>
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].aaaaaaaaaaaaaaaa, [object].aaaaaaaaaaaaaaab, ...,
[object].zzzzzzzzzzzzzzzz, 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.getElementsByTagName
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
getElementsByTagName.
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.fromCharCode(i);
if (previousProp.length < 3) {
properties = properties.concat(allProp(obj, newProperty));
}
if (typeof obj[newProperty] != 'undefined') {
properties.push(newProperty);
}
}
return properties;
}
var prop = allProp(document);
// code to test results
var s = [];
for (var i in prop) {
s.push(i + ' = ' + prop
+ ' = ' + document[prop]);
}
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 <[email protected]>
* Client-side Javascript and Netscape 4 DOM Reference available at:
*
http://devedge.netscape.com/library/manuals/2000/javascript/1.3/reference/frames.html
* Internet Explorer DOM Reference available at:
*
http://msdn.microsoft.com/workshop/author/dhtml/reference/dhtml_reference_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-developer/upgrade_2.html