W3C home > Mailing lists > Public > public-webapps@w3.org > January to March 2014

Re: Why can't we just use constructor instead of createdCallback?

From: Erik Arvidsson <arv@chromium.org>
Date: Tue, 18 Feb 2014 14:24:48 -0500
Message-ID: <CAJ8+GogZUw06DWLcc_j6qaCrriNRT_pHQJaS8tscvdzQYfROGw@mail.gmail.com>
To: Dimitri Glazkov <dglazkov@google.com>
Cc: Jonas Sicking <jonas@sicking.cc>, Boris Zbarsky <bzbarsky@mit.edu>, Ryosuke Niwa <rniwa@apple.com>, WebApps WG <public-webapps@w3.org>, "Edward O'Connor" <eoconnor@apple.com>, William Chen <wchen@mozilla.com>
On Tue, Feb 18, 2014 at 1:35 PM, Dimitri Glazkov <dglazkov@google.com>wrote:

> Here's an alternative proposal:
> 1) The Web developers are already aware of the fact that you can create
> new instances of JS objects without running their constructors with
> Object.create

These are not the instances you are looking for.

We need to have real instances here. @@create gives us the semantics for
doing this.

> 2) Let's make sure that when they call constructors directly (as in var b
> = new MyB(arg1,arg2);), the constructor is actually called.
> 3) When the parser instantiates the element, it does the equivalent of
> Object.create, so no constructor is called.

That would not set the internal state as needed. It would not know how to
associate the instance object with the C++ backing object for example.
Also, all the DOM methods are using brand checks (and not instanceof
checks) so the brand needs to be setup as well.

The solution is to call `MyElement[Symbol.create]()` which would setup the
internal state as needed. We can make this non writable, non configurable
which allows the implementation to skip calling any js code at that point
because the semantics is unobservable.

> It seems simple and easy to understand.

With ES6 it is possible to create instance objects without ever calling the
constructor (this is NOT possible in ES5) so maybe we should just give up
on having the parser calling the constructor?

Received on Tuesday, 18 February 2014 19:25:36 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 18:14:22 UTC