Determine if a value is Callable/Constructible

Caitlin Potter caitpotter88 at gmail.com
Mon Mar 30 17:51:42 UTC 2015


>On Mar 30, 2015, at 1:44 PM, Domenic Denicola <d at domenic.me> wrote:
>>From: Axel Rauschmayer [mailto:axel at rauschma.de] 
>>As in “makes sense to call”. In the past, `typeof x === 'function'” was an adequate test for checking whether it makes sense to call `x`.
>
I> tried to explain explicitly why I don't think this is true.
>
>>Since ES6, it isn’t, anymore.
>
>I disagree. The situation has not changed at all.

As I said above:

```js
var called = false;
function F() {
  called = true;
  throw new TypeError(“can’t call F()”);
}

F(); // Throws, but `called` is true

called = false;
class C {
  constructor() {
    called = true;
    throw new TypeError(“can’t call C()”);
  }
}

C(); // Throws, but `called` is false, because the constructor was never invoked
```

That distinction means that you can’t “really” [[Call]] a constructor, it’s just that the reason is slightly different from trying to [[Call]] an Array instance (or something)


More information about the es-discuss mailing list