Object.prototype.* writable?

Douglas Crockford douglas at crockford.com
Sat May 7 11:44:31 PDT 2011

On 11:59 AM, Oliver Hunt wrote:
> <rant>
> It does annoy me that these were not made immutable.  The safest way to create an object is still either with an object literal or new SomeFunction;
> I'm not convinced that Object.create added anything of value to the language, and certainly wouldn't recommend
> its use for general object creation.
> </rant>
I disagree. Object.create is the foundation of a system of delegation. 
This was the brilliant idea that JavaScript borrows from Self.

The best technique available now for general object creation is 
Object.create(null), which allows for making objects which do not 
inherit from Object.prototype. This is a better defense against 
unintended inheritance than use of Object.prototype.hasOwnProperty, 
which has multiple hazards.

I agree that the primordials should have been frozen, but as Brendan 
says, that ship has sunk. But a smart library can now do that job, so a 
page can elect to have the benefit of frozen primordials if it wishes.

More information about the es-discuss mailing list