01:56
<jschoi>

Has a Function.prototype.isConstructor, Function.isConstructor, or Reflect.isConstructor method been explored by TC39 before?

The only references on the web I can find of any discussion is https://esdiscuss.org/topic/add-reflect-isconstructor-and-reflect-iscallable and https://github.com/tc39/agendas/blob/master/2015/01.md. Apparently, Jason Orendorff presented about it, but there’s nothing in https://github.com/tc39/notes/tree/master/meetings/2015-01 about that.

01:58
<jschoi>
The only reason why I ask about it is because I’m writing a polyfill for Array.fromAsync right now and finding it not possible to match the spec. It needs to do what Array.from does and start with a new C only if C is a constructor and otherwise start with Array(0).
02:00
<jschoi>
Current polyfills for Array.from generally seem to cheat and check only if C is a function.
02:58
<devsnek>
jschoi: you can use a proxy to mimic IsConstructor
02:59
<devsnek>
but i think the reason this doesn't get brought up more is because IsConstructor is not a great check in practice. normal functions and many builtins will be true even though they're not intended to be used as constructors
03:45
<Domenic>
Yeah, the polyfill can match the spec by using https://esdiscuss.org/topic/add-reflect-isconstructor-and-reflect-iscallable#content-2
03:46
<Domenic>
And yeah, given that it's only really useful for polyfills, adding it to the language seems subpar.
14:36
<jschoi>

Hm, I wonder if that proxy in that post even needs a construct handler.

function isConstructor (obj) {
  var prox = new Proxy(obj, {});
  try {
    new prox;
    return true;
  } catch (err) {
    return false;
  }
}

…should work too, right?

14:44
<Richard Gibson>
no, because a constructor might have runtime constraints such as required arguments
14:48
<jschoi>
no, because a constructor might have runtime constraints such as required arguments
Ah, so new prox there might throw not necessarily because it’s not a constructor.
14:48
<jschoi>
I see.
14:49
<Richard Gibson>
exactly. That version would false-negative on input like class { constructor(length){ if(typeof length !== "number") throw new TypeError("length must be a Number"); } }
14:49
<Ashley Claymore>
Ah, so new prox there might throw not necessarily because it’s not a constructor.
the constructor could also have side-effects