On Jul 16, 2008, at 10:14 PM, Kris Zyp wrote:
Arguably, some of the need for direct prototype access is
alleviated by providing the clone method. However, there are still
plenty of other situations where it is useful.
I observe that __proto__ in SpiderMonkey- and Rhino-based JS is
mostly used for cases covered by Object.create, with a minority use-
case that we've discussed before initializing it to null in object
initialisers to make maps (dictionaries).
I am curious how Object.create covers this __proto__ use case of
making
objects with a defined proto. Doesn't Object.create create a new
object and
copy properties over?
ES3.1 draft dated 15-July-08:
15.2.3.6 Object.create ( O [, Properties] )
The create method creates a new object with a specified prototype.
When the static create method is called, the following steps are taken:
1. If Type(O) is not Object throw a TypeError exception.
2. Create a new object as if by the expression new
Object() where Object is the standard built-in constructor with that
name
3. Call the standard built-in function
Object.defineProperties with arguments Result(2) and Properties.
4. Set the internal [[Prototype]] property of Result
(2) to Result(1).
5. Return Result(4).
__proto__ allows objects with existing properties to
have their proto defined in constant time, but isn't Object.create
still
O(n), with n being the number of properties?
Object.create allows creation of a new Object instance with a
designated prototype object initializing [[Prototype]].
/be
_______________________________________________
Es4-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es4-discuss