Why are object initializer methods not usable as constructors?

Allen Wirfs-Brock allen at wirfs-brock.com
Wed Jul 27 14:58:48 UTC 2016

The most common case is the “methods” are designed to be used as constructors.  This has always be recognized for built-in methods in the ECMAScript specification  which says: "Built-in function objects that are not identified [in this specification] as constructors do not implement the [[Construct]] internal method unless otherwise specified in the description of a particular function.”.   When “concise methods” where add as part of Object Initializers and Class Definitinos this default was applied to them.  

You can still define constructible properties for Object Initializers, just not by using concise method syntax:

let classes = {
  Cat: function() {},
  Dog: function() {},
  Bird: class {}

let [c, d, b] = [new classes.Cat, new classes.Dog, new classes.Bird];

More information about the es-discuss mailing list