Out of curiosity, why are classes specified to have a [[Call]] internal
method instead of special-casing `typeof` and friends to work with them?
Somewhat of a tangent, but just a curious question on the design decision.

On Tue, Jan 17, 2017, 08:31 Claude Pache <[email protected]> wrote:

>
> > Le 16 janv. 2017 à 18:00, Michael Haufe <[email protected]> a
> écrit :
> >
> > The question came up recently on CLJS [1] on how to determine if an
> object is safe to call as a Constructor.
>
> The two following procedures will determine whether an object is a
> constructor without running it, according to ES6. (Whether it is safe to
> call it as constructor... you need first a definition of "safe".)
>
> (1) Using `class/extends`:
>
> ```js
> function isConstructor1(f) {
>     if (f === null)
>         return false
>     try {
>         class c extends f { }
>         return true
>     }
>     catch (e) {
>        return false
>     }
> }
> ```
>
> (2) Using `Proxy`:
>
> ```js
> function isConstructor2(f) {
>     var p = new Proxy(f, { construct() { return {} } })
>     try {
>         new p
>         return true
>     }
>     catch (e) {
>        return false
>     }
> }
> ```
>
>
> —Claude
>
> _______________________________________________
> es-discuss mailing list
> [email protected]
> https://mail.mozilla.org/listinfo/es-discuss
>
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to