Extended Object Literals to review
P T Withington
ptw at pobox.com
Mon Mar 14 13:34:51 PDT 2011
On 2011-03-14, at 14:29, Jorge wrote:
> On 14/03/2011, at 18:32, P T Withington wrote:
>> On 2011-03-13, at 18:15, Juan Ignacio Dopazo wrote:
>>>
>>>
>>> The idea behind it was to be able to walk down the prototype chain by doing
>>> o.constructor.prototype.contructor.proto... But then I realized that's not
>>> the case even in today's javascript.
>>
>> I agree that we need this. (...)
>
> Isn't that the purpose of Object.getPrototypeOf() ?
If I have a class `c` whose superclass is `s`, I'm trying to understand how I can get from an object that is an instance of `c` to the superclass. I believe the current desugaring that Alan proposed, which obeys Brendan's recommendation that `constructor` be a property of the prototype results in:
o = new c();
o.constructor === c
o instanceof c => true
o instanceof s => true
o.constructor.prototype instanceof s => true
but:
o.constructor.prototype.constructor === c
?
I don't see how I can recover `s` from `o` (or `c`), which seems like a useful operation. What am I missing?
More information about the es-discuss
mailing list