Usually you'll get away with that, but I'd recommend you don't. (Not least because I'd recommend using class
syntax if you're going to use constructor function hierarchies, not ES5-style patterns, and class
sets things up correctly for you automatically.)
For a long time, although JavaScript set the constructor
property on the default object it assigned to the prototype
of a function, it didn't use it for anything. But userland code sometimes did, for the obvious purpose: To get the constructor function that (probably) constructed an object. As of ES2015, JavaScript itself uses the constructor
property for that too, in places where it's creating a new object from an existing one, such as a new array from an existing array (for instance, slice
), or a new RegExp
from an existing RegExp
(it does that behind the scenes when you use a regular expression in String#split
), a new promise from an existing promise (for instance, then
), etc.
So if you leave your hierarchy with the wrong effective constructor
property, operations expecting it to be correct will fail. But it's rare for an operation to actually use it, if you're not subclassing a built-in (and if you are, again, use class
) and you don't write code to use constructor
explicitly, it won't get used for anything.