Reputation: 2890
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?
Upvotes: 1
Views: 37
Reputation: 878
Because you overwrote the original prototype which knew the identity of the constructor.
Upvotes: 3