On 03.10.2010 0:58, Dmitry A. Soshnikov wrote:
 On 03.10.2010 0:51, Brendan Eich wrote:
On Oct 2, 2010, at 6:49 AM, Jorge wrote:

On 02/10/2010, at 15:29, Brendan Eich wrote:
On Sep 6, 2010, at 1:43 AM, Dmitry A. Soshnikov wrote:

For what to create a proxy? It's only for catch-traps (yes, it may be used additionally to create a _catcher_ with "Array" [[Class]], but without additions -- i.e. if a user wants just to inherit from Array.prototype and to have all arrays' stuff -- proxies are not needed to him).
Proxies are required to update length to be one greater than index (property name-string P such that ToString(ToUint32(P)) == P and ToUint32(P) is not 2^32 - 1) when setting an indexed property. Array's magic [[Put]] is not inherited.
Why not simply spec an Array.create() ?

-no need to redefine what an array is.
It's not clear from kangax's blog post that an array with an extra object on its prototype chain before Array.prototype is enough, but if it is, then yes: Array.create is simpler and more direct than using proxies.


-no need to learn new concepts ( we're used to Object.create() already )
There's definitely a new concept here. Right now you can't create an array instance whose [[Prototype]] is not some Array.prototype. Array.create changes that.


-easy to grasp, expected behaviour.
-it's a 3-liner that would take no more than 3 minutes to implement in JS in any current UA.
-it would just need to be in the ES specs.
"3-liner", "3 minutes" and "just" need demonstration. Are you writing the code and spec patches? Talk is cheap :-|. Arrays are highly optimized in modern engines (up to some array sparseness limit). Adding a prototype object shouldn't hurt if the new proto-object contains no indexed properties, though.


Off-topic: what's wrong with the es-archive? Take a look please: https://mail.mozilla.org/pipermail/es-discuss/2010-October/thread.html I sent reply with implemented extended Object.create and meta-constructor (meta-class) but it's not displayed there. Maybe it's not reached es-discuss at all? If it didn't (by some reason), consider this implementation (http://gist.github.com/607668). It allows to create objects of any [[Class]] with needed inheritance chains.


Another variant btw, is just to set special internal property for the constructor. This property specifies the [[Class]] of objects created by the constructor.

function Foo() {
  this.push.apply(this, [1, 2, 3]);
}

Object.setObjectsClass(Foo, "Array");

var foo = new Foo();
foo.length // 3
Array.isArray(foo); // true
// etc.

Dmitry.

/be

_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss


_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to