I have the following piece of code:
function University(name) {
this.name = name
}
University.prototype = {
sayName: function() {
console.log(this.name)
},
toString: function() {
console.log("WUSTL")
}
};
var univ = new University("Washington University");
console.log(univ instanceof University);
console.log(univ.constructor == University); // false
console.log(univ.constructor == Object); // true
can anybody help to explain why the constructor of the instance of 'University' got changed to Object instead of University?
University.prototype.constructor = University;. An useful link about Prototypes.