Default call constructor behavior

Isiah Meadows isiahmeadows at gmail.com
Mon Oct 26 02:59:02 UTC 2015


According to the current call constructor proposal, the behavior for
classes without call constructors is to unconditionally throw.
Shouldn't this be changed to automatically calling the constructor? I
see this as better for several reasons:

1. It's consistent with most of the builtins, including all of the new
ES6 types.
2. It's easier to integrate into several libraries. I've run into a
ton of issues with trying to add support for ES6 classes in a specific
library written for ES5 for this reason. I can use `C.apply(null,
args)` instead of `new (Function.apply(C.bind,
[null].concat(args)))()`.
3. It's easier to use in functional programming. (`titles.map(Book)`
instead of `titles.map(title => new Book(title))`)
4. It's easier to partially apply. It would make the implementation of
the proposed Function.prototype.partial very easy, as well as simplify
and speed up Function.prototype.bind for classes, as assumptions can
be made.

-- 
Isiah Meadows


More information about the es-discuss mailing list