Le 07/05/2011 20:44, Douglas Crockford a écrit : > 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. I agree. Object.create is what should have been present in the first place. Even before functions as constructors. Even before putting Object.prototype as the default prototype object for the object literal (in ES5, calls "new Object()" which sets the [[Prototype]] to the standard built-in Object prototype object. See 11.1.5 then 15.2.2.1 step 4). One strawman even suggests an extension to object literals in order to declare the prototype object [1] Object.create is the "easiest" abstraction based on which, other constructs can be created. It gets back to the basic definition of what an object is (ES5 4.3.3): "An object is a collection of properties and has a single prototype object. The prototype may be the null value." Before Object.create, there was no easy way built-in in the language to create an object following this definition. You had to create the abstraction yourself. With Object.create, the abstraction is natively here (properties are also considered with the second optional argument).
David [1] http://wiki.ecmascript.org/doku.php?id=strawman:obj_initialiser_meta _______________________________________________ es-discuss mailing list [email protected] https://mail.mozilla.org/listinfo/es-discuss

