Determine if a value is Callable/Constructible

Axel Rauschmayer axel at rauschma.de
Mon Mar 30 08:12:54 UTC 2015


>> It doesn’t seem that big of a deal, but one risk is: people mistaking a class for a constructor, trying to subclass it as if it were a constructor and things failing silently.
>> 
> Can you give an example of what you mean?

```js
class MySuperClass {}

// This function assumes that MySuperClass is an ES5 constructor function
function MySubConstructor(foo) {
    MySuperClass.call(this);
    this.foo = foo;
}
MySubConstructor.prototype = Object.create(MySuperClass.prototype);
MySubConstructor.prototype.constructor = MySubConstructor;
```

-- 
Dr. Axel Rauschmayer
axel at rauschma.de
rauschma.de



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20150330/d9b16e1e/attachment.html>


More information about the es-discuss mailing list