Accesssing ES6 class constructor function

James Treworgy jamietre at gmail.com
Thu Jan 5 18:28:17 UTC 2017


@Oriol

> This has never been a guarantee

I mean a guarantee that I can simply invoke a function. What the function
actually does is of course beyond my control.

>About the stringifications problems

I'm not really concerned about this, but rather just noting it out as
something that is fundamentally different -- we now have something of type
"function" where Function.protoype.toString() doesn't evaluate to legal
javascript function declaration. But this point is a distraction from the
real concern, yeah -- nothing was ever guaranteed ehre

@Tiddo

(slaps forehead) this might - actually - be enough. I need to think about
it a bit. The issues of concern are: ability to name the resulting class
dynamically (which I remember some quasi-hack involving using dynamic
properties of an object that it's possible), and having a return value from
"super" (is that possible? to be compatible with ES5 prototypes that return
something from the constructor);

But this does kinda get to the major issue... I think my head is so far in
how we do things with prototypes that it didn't occur to me to just use an
ES6 language feature. I think the biggest difficulty would be creating an
implementation that works with native ES6 constructs as well as ES5 or
transpiled classes, but seems like it should be possible.

On Thu, Jan 5, 2017 at 1:06 PM, Oriol _ <oriol-bugzilla at hotmail.com> wrote:

> > It means testing something for typeof "function" no longer guarantees it
> can be invoked without error.
>
> This has never been a guarantee. Consider this code
>
> ```js
> function Test() {
>   throw new TypeError();
> }
> typeof Test === 'function';  // true
> Test();  // TypeError
> ```
>
> About the stringifications problems, I don't understand what you are
> attempting to do. Usually you shouldn't need to stringify a function.
> Probably there is a better approach.
>
> > There seems to be no method [...] to invoke a class constructor except
> by creating an instance of the class.
>
> Well, the point of constructors is creating instances. If you don't want
> the instance you can just discard it, but then why call the constructor?
>
> > So classes are fundamentally different than prototype contructors in how
> we can use them, far more than syntactic sugar
>
> Not that different. You can usually translate one syntax to the other, but
> you may need ES6 features like `new.target`, `super` or `setPrototypeOf`.
>
>
> -- Oriol
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20170105/4003f4e3/attachment.html>


More information about the es-discuss mailing list