@@new
Erik Arvidsson
erik.arvidsson at gmail.com
Wed Jun 18 08:33:03 PDT 2014
What about the other direction?
class B {
constructor(x) {
this.x = x;
}
static [Symbol.create]() {
var o = super();
weakMap.set(o, 12345678); // DOM wrapper foo
return o;
}
}
function C(x) {
B.call(this, x);
}
C.__proto__ = B;
C.prototype = {__proto__: B.prototype};
I think the most concerning part of this proposal is that
`constructor(...)` gets replaced by `static [Symbol.new](...)` with strange
semantics regarding `this`. If we instead had @@new call constructor by
default I think most of these concerns go away but then again we are back
to two initialization functions and the possibility to observe an object
that never went through its constructor.
On Tue, Jun 17, 2014 at 8:03 PM, Jason Orendorff <jason.orendorff at gmail.com>
wrote:
> On Tue, Jun 17, 2014 at 6:55 PM, Erik Arvidsson
> <erik.arvidsson at gmail.com> wrote:
> > How does this work with legacy classes?
> >
> > function B() {
> > this.x = 1;
> > }
> > class C extends B {}
>
> That works!
>
> `new C` desugars to `C[@@new]()`. C doesn't have a @@new method of
> its own, so it inherits `Function.prototype[@@new]`.
>
> The algorithm for that method is given in the proposal. Step 1 selects
> the right prototype here (C.prototype), and step 4 calls B as desired.
>
> -j
>
--
erik
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20140618/436eab52/attachment.html>
More information about the es-discuss
mailing list