First, I am not completely against the proliferation of native types and ECMA-262 5th ed . solves the problems mentioned in other answers and related articles for us in a good manner. See These slides for a good overview.
You can extend any object and define property descriptors that control the behavior of these properties. A property can be made without an enumerated value when accessing the properties of objects in a for..in loop, this property will not be included.
Here you can define the getType method for the Object.prototype itself and make it non-enumerable:
Object.defineProperty(Object.prototype, "getType", { enumerable: false, writable: false, configurable: false, value: function() { return typeof this; } }); // only logs "foo" for(var name in { "foo": "bar" }) { console.log(name); }
The getType function above is mostly useless, as it simply returns a typeof object , which in most cases will be just an object, but it is only available for demonstration.
[].getType(); {}.getType(); (6).getType(); true.getType();
source share