Determining if an object can be constructed

Michael Haufe tno at thenewobjective.com
Mon Jan 16 17:00:40 UTC 2017


The question came up recently on CLJS [1] on how to determine if an object
is safe to call as a Constructor.

Traditionally one uses try {... x = new foo() ... } catch(e) { ... x =
foo() }


In the list of well-known symbols [2] there doesn't seem to be a way to
reference [[Construct]] to perform a test to avoid the try/catch.  In the
following[3] though there is reference to Symbol.create which doesn't seem
to be in the spec but seems to be the one to look for. Can we get
clarification on if it is possible to determine if an object can be
constructed before attempting it?

[1] <
https://groups.google.com/forum/#!msg/comp.lang.javascript/nSesJfznwjg/rKiQOzkYEwAJ
>
[2] <http://www.ecma-international.org/ecma-262/7.0/#sec-well-known-symbols>
[3] <
https://github.com/lukehoban/es6features/blob/master/README.md#subclassable-built-ins
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20170116/cc60ccd7/attachment.html>


More information about the es-discuss mailing list