"not a Date object" vs. "not an object with [[Class]] of ''Date''"

Oliver Hunt oliver at apple.com
Fri Oct 1 18:24:21 PDT 2010


I really don't like the idea of using proxies simply to essentially create an array with a custom prototype.

My understanding of what is wanted (in terms of subtyping an array) is an ability to have something like

var arr = new MyArray()

Where 'new MyArray' behaves in essentially the same manner as 'new Array', however it produces an object along the lines of

<an array instance> <- <a custom prototype> <- <array prototype>

In a engine that support mutating proxies this would be equivalent to:

function MyArray() {
    var result = Array.apply(null, arguments);
    result.__proto__ = MyArray.prototype;
    return result;
}

MyArray.prototype = Object.create(Array.prototype);

If my understanding of this desired behaviour is correct, i think a better solution would be to make an API that could generate the MyArray function.

--Oliver


On Oct 1, 2010, at 6:14 PM, Brendan Eich wrote:

> KangaX brought this up in
> 
> http://perfectionkills.com/how-ecmascript-5-still-does-not-allow-to-subclass-an-array/
> 
> and proxies are of no avail. To make an array-like using ES5 is possible but [[Class]] won't lie, and that is still true with Proxy.create instead of Object.create.
> 
> As we have discussed, [[Class]] is very much a nominal type tag, so it is not something we want to be forged by an impostor. But perhaps as Allen mentioned in the TC39 meeting this week, [[ClassName]] could be separated from [[Class]], and forged without problem. Proxies would want to be able to present a specific [[ClassName]], but a non-varying one -- so probably a trailing Proxy.create parameter. Thoughts?
> 
> /be
> 
> 
> 
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss



More information about the es-discuss mailing list