Accesssing ES6 class constructor function

Oriol _ oriol-bugzilla at hotmail.com
Thu Jan 5 18:06:28 UTC 2017


> 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/c7856bdc/attachment-0001.html>


More information about the es-discuss mailing list