It will not if you have

```js
function Foo() {
  Bar.call(this);
}
```

as generic way to extend classes in your old style logic, something that
will inevitably fail the moment you do

`Foo.prototype = Object.create(Bar.prototype);`

with `Bar` that comes from ES6 and it has been defined as `class` instead
of old style function.

This is an interoperability problem where the new world cannot work in the
old one and having `typeof Constructor === 'function'` means any old
inheritance based code won't even bother wrapping the .call behind a try
catch.

I hope I've described the problem in a better way ... this choice breaks
badly old patterns and I am not sure yet I understand advantages about it.

Also, if you ask me, I think `Array` example I proposed is a bad spec about
how the `Array` behaves, and subclassing in general in ES3. We all know
that, now we have triple behavior in ES6.

Regards




On Thu, Aug 21, 2014 at 3:16 PM, Tab Atkins Jr. <jackalm...@gmail.com>
wrote:

> On Thu, Aug 21, 2014 at 2:03 AM, Andrea Giammarchi
> <andrea.giammar...@gmail.com> wrote:
> > This is also a precedent that suggest `Object.create(Generic.prototype)`
> is
> > useless when the `Generic` is ES6 class due inability to initialize it
> later
> > on: a very "bad news" for prototypal inheritance.
> >
> > Accordingly, interoperability with old code (the "one JS" myth) is
> > compromised and prototypal inheritance won't be "fully portable" with
> > user-land classes.
> >
> > Latter is not necessarily unexpected since we know other cases that could
> > fail, i.e.
> >
> > ```js
> > var a = Object.create(Array.prototype);
> > Array.call(a, 1, 2, 3);
> > a; // still empty
> >
> > Array(1, 2, 3); // [1,2,3]
> > ```
>
> I don't generally see this kind of "inheritance" used; it seems like a
> weird way to say "var a = new Array(1, 2, 3);".
>
> I do commonly see code like:
>
> ```
> function Foo() {
>  ...
> }
> Foo.prototype = Object.create(Bar.prototype);
> ```
>
> Which always works and will continue to work in the future.
>
> ~TJ
>
_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to