In JavaScript, every function's prototype object has a non-enumerable property constructor
which points to the function (EcmaScript §13.2). It is not used in any native functionality (e.g. instanceof
checks only the prototype chain), however we are encouraged to adjust it when overwriting the prototype
property of a function for inheritance:
SubClass.prototype = Object.create(SuperClass.prototype, {
constructor: {value:SubClass, writable:true, configurable:true}
});
But, do we (including me) do that only for clarity and neatness? Are there any real-world use cases that rely on the constructor
property?