Here’s the code that explains the question further:
function MyConstructor() {}
var myobject = new MyConstructor();
myobject.constructor == MyConstructor; // true
function MyConstructor() {}
MyConstructor.prototype = {};
var myobject = new MyConstructor();
myobject.constructor == MyConstructor; // false
So, why is the second block false?
The
constructorof the created object changes because theconstructorof its prototype changes. This is why you generally shouldn’t overwrite the prototype. If you do, make sure to set it back later: