On Oct 13, 2011, at 5:15 AM, David Bruant wrote:

> Le 13/10/2011 02:03, Allen Wirfs-Brock a écrit :
> ...

> So far so good
> 
>> console.log(s instanceof Array); //true
> i think that this should be false.
> Object.getPrototypeOf(s) is the value of Object.getPrototypeOf(this) in the 
> constructor which is the anonymous function 'prototype' property (fresh 
> object inheriting from Object.prototype with the methods you added).
> My understanding of <| is that it sets the [[prototype]] property and nothing 
> else. Consequently, I think that the semantics of "Array <| function(...){}" 
> is to create a function with the prototype chain as follow:
> (anon function)  --> Array --> Function.prototype --> Object.prototype --> 
> null
> And unless otherwise specified, (anon function).prototype is a fresh object 
> inheriting from Object.prototype (not Array.prototype)

that was the original idea but a couple of months ago the <| spec was updated:
 "If the LHS operand has a property named prototype and the RHS operand is a 
function expression then the [[Prototype]] of the function object is set to the 
LHS object and the prototype property of the new function is set to a new 
object whose [[Prototype]] is the value of the LHS’s prototype property."
(http://wiki.ecmascript.org/doku.php?id=harmony:proto_operator )

> 
> But I think that the following should work:
> -----
> var SubArray = function(...values) {
>   return Object.getPrototypeOf(this) <| [...values];
> }
> SubArray.prototype = Array.prototype <| {/*additional "subclass" methods*/};

you'd also need to include a constructor property in the new object in order to 
make s instanceof SubArray work properly.  The <| spec was revised as above in 
order to ensure this all works automatically.

Allen

_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to