Determining if an object can be constructed

T.J. Crowder tj.crowder at farsightsoftware.com
Mon Jan 16 17:24:37 UTC 2017


Related: There's [a proposal][1] for `Reflect.isConstructor` (and
`Reflect.isCallable`) which addresses this very gap. There seem to be some
questions around `Reflect.isCallable` (whether it should be true or false
for class constructors, since you can't [[Call]] them), but I didn't see
issues raised around `Reflect.isConstructor`. Seems a bit stalled, though.

[1]
https://github.com/caitp/TC39-Proposals/blob/master/tc39-reflect-isconstructor-iscallable.md

-- T.J.


On Mon, Jan 16, 2017 at 5:00 PM, Michael Haufe <tno at thenewobjective.com>
wrote:

> 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>
>
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20170116/4c3b1e4e/attachment.html>


More information about the es-discuss mailing list