Extended Object Literals to review

Juan Ignacio Dopazo dopazo.juan at gmail.com
Sat Mar 12 14:58:27 PST 2011


Correct me if I'm wrong, but I think it should be like this:

function S() {}

function C() {
Object.defineProperty(this, 'constructor', {
 value: C,
enumerable: false,
 writable: false,
configurable: false
 });
}
C.prototype = Object.create(S.prototype);

var o = new C();
console.log(o.constructor == C); // true
console.log(o.constructor.prototype.constructor == S); // true

Juan


On Sat, Mar 12, 2011 at 4:36 PM, Allen Wirfs-Brock <allen at wirfs-brock.com>wrote:

> good point, the desugaring should be:
>
> function c() {};
> c.prototype=Object.create(s,protoype,{'constructor': { value:c, enumerable:
> false, writable: false, configurable:false}});
>
> We can debate about the attributes of the constructor (and the
> constructor's prototype) property but my stake in the ground is that these
> should be frozen because they are defined declaratively.
>
> On Mar 12, 2011, at 11:06 AM, Michael Haufe wrote:
>
> On Sat, Mar 12, 2011 at 11:02 AM, Allen Wirfs-Brock <allen at wirfs-brock.com
> > wrote:
> [...]
> > class c {
> >    <proto: s.prototype>
> > }
>
> > class c {
> >    <superclass: s>
> > }
>
> > both are equivalent to:
>
> > function c() {};
> > c.prototype=Object.create(s.prototype);
> [...]
>
> So if "var b = new c", then "b.constructor" will be "s" instead of "c"?
>
>
>
>
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20110312/b8b9fae3/attachment-0001.html>


More information about the es-discuss mailing list