On 14/03/2011, at 21:34, P T Withington wrote:
> On 2011-03-14, at 14:29, Jorge wrote:
>> 
>> 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?

ISTM, you would just need to follow the [[prototype]] chain, like so:

function S () { }
S.prototype.constructor= S;

function C () { }
C.prototype= new S;
C.prototype.constructor= C;

o= new C;

do {
  o= Object.getPrototypeOf(o);
  console.log(o && o.constructor);
} while (o);

--> OUTPUT:

function C() { }
function S() { }
function Object() { [native code] }
null

No ?
-- 
Jorge.
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to