Adam L Barrett
Jul 27, 2017 · 1 min read

I drank the Eric Elliott kool-aid on this issue a long time ago, and fully agree about everything regarding factory functions vs classes.

But, I think the example with Promises is a bad illustration of the issue. The error throwing example isn’t because of the `constructor` function, or lack of `.of()` or classes vs factories, it’s because of a required argument.

If you were to change the implementation of Promise to not require a executor function, the example works fine:

class PromiseX extends Promise {
constructor(executor = (res)=>res()) {
super(executor);
}
}
// Return an empty instance of any type?
const empty = ({ constructor } = {}) => constructor ?
new constructor() :
undefined
;
const foo = PromiseX.resolve(10);
console.log(
empty(foo) // Promise{[[PromiseStatus]]: "resolved",
// [[PromiseValue]]: undefined }
);

I fully agree about the superiority of factories over classes in almost every instance, but this particular example does not match the accompanying message and should maybe be exchanged for something that illustrates the point better.

That nit-pik aside, great article. Thanks, Eric, for writing these.

    Adam L Barrett

    Written by

    Games, the Web, and Flicks