Determine if a value is Callable/Constructible

Axel Rauschmayer axel at rauschma.de
Mon Mar 30 09:19:52 UTC 2015


> On Mar 30, 2015 10:54 AM, Axel Rauschmayer <axel at rauschma.de> wrote:
> >>>
> >>> ```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;
> >>> ```
> >>
> >>
> >> so if MySuperCall didn’t have the throw on [[Call]] behavior the above would work just fine.
> >
> >
> > In general, I’d expect this kind of subclassing to fail, due to the new instantiation protocol. Wrong?
> 
> Would work fine if throw semantics removed and invoked as
> ```js
> new MySubConstructor();
> ```
> Just like ES5.
> 
> If invoked as
> ```js
> MySubConstructor();
> ```
> would fail just like ES5.
> 
> Throwing on [[Call]] is a compatibility hazard.
> 


Don’t the different assumptions as to where the instance is allocated ever clash here? What if `MySuperClass` were:

```js
class MySuperClass extends Error {
}
```

-- 
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/28068cd4/attachment-0001.html>


More information about the es-discuss mailing list