Javascript contains hidden properties in many objects, I first discovered this when DoctorDan from the slackers forum demonstrated a technique to get the text from a regular expression object without specifying the source property. Later I found a post by John Resig about weird IE behavior again with -1 properties.
So I decided to experiment and write a little script to investigate further. I discovered that it’s possible to access strings of global object names. For example:-
alert(Boolean[-6]); alert(typeof Boolean[-6]);
It seems that Firefox at least stores names of objects in “-6″, the example above returns the value “Boolean” as a string. Here’s a few examples I posted slackers which use Objects to create strings.
This is the simple script I wrote to find the properties, feel free to experiment and find any other “hidden” gems.
function inspectObject(obj) {
var prop;
var props = [];
for(var i=-1000;i<1000;i++) {
if(i > 0) {
prop = obj[String.fromCharCode(i)];
if(prop != null) {
props.push(String.fromCharCode(i) + '=' + prop);
}
} else {
prop = obj[i];
if(prop != null) {
props.push(i + '=' + prop);
}
}
}
return props;
}
x=function x(){};
inspectObject(x)