I want to create an object with a hidden property(a property that does not show up in a for (var x in obj loop). Is it possible to do this?
It's a bit tricky!
function secret() {
var cache = {};
return function(){
if (arguments.length == 1) { return cache[arguments[0]];}
if (arguments.length == 2) { cache[arguments[0]] = arguments[1]; }
};
}
var a = secret();
a.hello = 'world';
a('hidden', 'from the world');
If you are a real pro though, you can do it this way!
var a = new (secret())();
a.hello = 'world';
a.constructor('hidden', 'from the world');
Now if you look a in firebug it will be an object ... but you know better! ;-)