Occasionally there is a JS framework or library that thinks it’s a really wise idea to add some net new features to the prototype of Object or Array. I can’t find any more examples right now, but I do remember that I’ve had problems with that before. Of course, doing so breaks the good old for(...in...) loop, because suddenly those properties are now enumerated too. To get around it you have to check every enumerated property with .hasOwnProperty() before accessing. Which is cumbersome, when trying to write robust code.
So I got wondering – is there some way that I could make my own objects so, that they don’t inherit from Object? Initial playing around with .prototype yielded no results. Perhaps there is some trick to it? Or will everything always inherit from Object and there’s nothing I can do about it?
Added: I guess I should have noted that I want it for client-scripts in browsers, and compatibility should include IE6, or at least IE7. Other browser version requirements are more lenient, though the more the better, of course. (Yes, sadly, the corporate world still lives in IE-world…)
In ECMAScript 5 you can pass
nulltoObject.create: