And why can't you call the superconstructor at the end?
It'd work the exact same except it could overwrite some of the
properties you wrote... but since those things would more likely be in
prototype, it's not much of an issue.

On Fri, Nov 11, 2011 at 10:05 PM, Juan Ignacio Dopazo
<dopazo.j...@gmail.com> wrote:
>> On Fri, Nov 11, 2011 at 4:23 PM, Xavier
>> MONTILLET <xavierm02....@gmail.com> wrote:
>>
>> Object.getPrototypeOf(this) === Point.prototype <=> this instanceof Point
>>
> Actually, no. this instanceof Point => Object.getPrototypeOf(this) ===
> Point.prototype, but not the other way around.
>
>>
>> And I don't understand your problem >_ <
>>
> The problem is this that when you do prototypical inheritance using
> constructors you usually call the superclass before any of the subclass
> constructor code. So if you just seal(this) in the constructor of the
> superclass the subclass can't add properties to the object.
> function Person(name) {
>   this.name = name;
>   Object.seal(this);
>   console.log(this instanceof Person, Object.getPrototypeOf(this) ===
> Person.prototype); // true false when doing new Pirate()
> }
> function Pirate() {
>   Person.apply(this, arguments);
>   this.eyepatch = true;
> }
> Pirate.prototype = Object.create(Person.prototype);
> var captain = new Pirate('Blackbeard');
> console.log(captain.eyepatch); // undefined
>
> Juan
_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to