It would be technically possible for such a thing to occur, but it's a code smell.
function Klass(){
this.constructor = Klass;
}
const k = new Klass();
console.log(k.hasOwnProperty('constructor'), k);
(You might also see it when someone improperly extends a function class)
Object instances are expected to have a .constructor
property on their prototype, not directly on the instance. If property is directly on the instance, that'll cause problems when someone tries to use one of the common methods to iterate over own-properties and finds constructor
there.
Another reason why it should be on the prototype and not on the object itself is to take advantage of prototypal inheritance. If a property can exist on one object, on the prototype, better to do that than to duplicate that property everywhere, for every instance. And the constructor property is already automatically on the prototype, so there shouldn't be any need to mess with it anyway.
For similar reasons, class methods are often on the class prototype when possible, rather than duplicated for every single instance. That is, you have all instances inheriting from one prototype with the method, rather than all instances having their own-property method. That is, it's not that good to have
class Klass {
constructor() {
this.method = () => console.log('method');
}
}
const k = new Klass();
k.method();
with the method duplicated for every instance, when you can instead do
class Klass {
method() {
console.log('method');
}
}
const k = new Klass();
k.method();
and have it only on the prototype.