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

Dmitry A. Soshnikov dmitry.soshnikov at gmail.com
Sat Oct 2 14:14:56 PDT 2010


  On 03.10.2010 1:06, Brendan Eich wrote:
> On Sep 6, 2010, at 7:17 AM, Dmitry A. Soshnikov wrote:
>
>> On 02.10.2010 17: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.
>>>
>> Yep, true, but if we have ability to specify the [[Class]] -- we'll have overloaded [[DefineOwnProperty] (or [[Put]] in ES3).
>>
>> Here's this ad-hoc (with using __proto__ injection) implementation: http://gist.github.com/607668
>>
>> By the way, at first glance, the ability to specify [[Class]] with using first level of inheritance is not so convenient and needed.
> Indeed. Also, I would not say this shows the abilitiy to specify [[Class]] as if that internal property could be specified as "Array" for a non-Array instance -- all you are doing is making an Array instance whose [[Prototype]] links to a user-specified object.

Yeah, of course, but it's just a shim with resources I have (JS) :) At 
lower level of implementation, I'd operate with different approach.

> That's novel in ES5, i.e., without settable __proto__ and without Array.create as Jorge pointed out.
>

Yes, but Array.create should do the same. Implementation is abstract and 
isn't essential. The end result is essential. With the same end result 
all implementation fit (if to consider only the semantics of course).

> /be
>
>
>> Because with the same success we may create a simple array and augment it with needed properties. However, starting from the second and later inheritance levels -- it may be convenient.
>>
>> This is if to talk about prototypal inheritance. If to consider class-based inheritance (that is, with using constructors), possibly it can be sense in the special meta-constructor (a constructor of constructors) which may specify, objects of what kind (of what [[Class]]) a newly created constructor may produce.
>>
>> P.S.: in addition, the Proxy constructor may also accept className parameter. But repeat -- proxies are needed to trap the property access. If a user just want to have Array.prototype in inheritance chain and at the same time have an object of the "Array" kind, he just creates it with specifying this kind. He don't need to write a proxy's handler for that. Howerver, if he does need the catcher -- he creates a proxy of "Array" kind.
>>
>> Dmitry.
>>
>>> /be
>>>



More information about the es-discuss mailing list