Subclassing Function

Allen Wirfs-Brock allen at wirfs-brock.com
Thu May 7 20:25:11 UTC 2015


On May 7, 2015, at 12:50 PM, Francisco Tolmasky wrote:

> In the existing implementations I’ve tried, it appears I can’t do this:
> 
> class SuperFunction extends Function { }
> 
> (also tried with constructor(str) { super(str) })
> 
> It “works”, but the resulting new SuperFunction(“return 5”) is just a Function, not a SuperFunction. Is Function meants to be an exception to the subclassing built-ins, or should it also work?

Nope, it's supposed to work. `Object.getPrototypeOf(new SuperFunction("")` should be SuperFunction.prototype and `new SuperFunction("") instanceof SuperFunction` should be true.

You need to file a bug report on the implementations where you tried it.  Sounds like they still have some work to do

Allen



More information about the es-discuss mailing list