Imagine a language made out of constructors:
constructor Person(name) { this.name = name } new Person
It is possible to call constructor without allocating object:
constructor add(a, b) { return a + b } add(2, 3) //5
Still it is a constructor:
new add(2, 3) //add {}
It may seems not a big deal, but core primitives — Object
, Array
, Function
, Number
, String
, Boolean
, RegExp
, Date
— are constructors too. So once language was extended with syntactic sugar for class definition, it remained producing constructors:
class Foo {} Foo === Foo.prototype.constructor Foo instanceof Function //true