IsConstructor

Allen Wirfs-Brock allen at wirfs-brock.com
Wed Jun 11 09:04:57 PDT 2014


On Jun 11, 2014, at 8:49 AM, André Bargull wrote:

> 
> From [1]:
> ```javascript
> function IsConstructor(o) {
>  try {
>    new (new Proxy(o, {construct: () => ({})}));
>    return true;
>  } catch(e) {
>    return false;
>  }
> }
> ```
> 
> This IsConstructor implementation does not trigger any side-effects and works even when the underlying constructor requires arguments etc.
> 
> 
> 
> [1]
> https://github.com/anba/es6draft/blob/master/src/test/scripts/suite/lib/assert.js#L53-L60

+1.  

I was just about to write and post the equivalent.

Allen


More information about the es-discuss mailing list