On Nov 17, 2014, at 11:06 AM, Brendan Eich wrote:
> Allen Wirfs-Brock wrote:
>> ```js
>> Array[Symbol.isArray]] = true; //note, this is a constructor property, not
>> an Array.prototype property.
>
> Minomer, then -- how about Symbol.isArrayClass?
perhaps, I have a negative reaction to including the work "class" but can
probably live with it.
>
>> we also change Array.prototype.concat to do the above Array.isArray test
>> instead of using @@comcatSpreadable and change JSON.stringify to use this
>> test where it current checks for an exotic array object.
>>
>> Then we have the following:
>>
>> assert(Array.isArray( [ ] )); //just like ES5
>> assert( ! Array.isArray( Object.create(Array.prototype))); //just like ES5
>
> How so? True:
>
> js> Array.isArray(Array.prototype)
> true
> js> Array.isArray(Object.create(Array.prototype))
> false
>
> but constructor isn't shadowed:
>
> js> Array.prototype.constructor
> function Array() {
> [native code]
> }
> js> Object.create(Array.prototype).constructor
> function Array() {
> [native code]
> }
Shit, you're right. This is the hard case for legacy compat using this
technique.
I think I see a way to make this give the legacy answer, but I suspect I can't
make it give the same answer for
Array.isArray(new Proxy(Object.create(Array.prototype), { }));
May limiting the WTF=ness to that case isn't so bad.
>
>> assert (new class extends Array{}); //ES6 Array subclass instances answer
>> true unless the subclass over-rides the static @@isArray property
>> assert(new class extends Array {
>> constructor() {return {}};
>> }); // even if the subclass instance isn't an exotic array object (this is
>> an improvement over the current ES6 spec. which says that
>> //isArray answers false in this case
>> assert(new Proxy( [ ], { }); //because it's all done with property access,
>> no instance inspection required.
>
> (These want Array.isArray inside assert, of course.)
of course
>
>> assert( ! new Int32Array(10)); //not array-like, just like ES5
>>
>> However, I think we should experiment with giving %TypedArrau% is true
>> valued @@isArray property. I'm guessing that this change won't actually
>> break anything.
>
> Probably ok.
>
>> the above proposal completely decouples Array.isArray from exotic array
>> object checking or any other direct instance inspection. Everything works at
>> the property access level and so is (by default) transparent to proxies and
>> completely controllable at the ES cod level.
>
> Righteous goal!
>
> /be
>
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss