When I execute the following js code, I found something weird:
function Contact(name, email) {
this.name = name;
this.email = email;
}
Contact.prototype = {
a: 10,
b: 20
};
var obj = new Contact('ssj', 'ssh');
obj.a = 'ssjssh';
console.log(obj);
console.log(Contact.prototype);
//output: { name: 'ssj', email: 'ssh', a: 'ssjssh' },{ a: 10, b: 20 }
so my question is that why obj.a = 'ssjssh' only add a property in obj, instead of change the property a in Contact.prototype?