I am learning javascript and the following code confuses me.
//a constructor function
function Person() {
}
//creating object person1
var person1 = new Person();
//changing the prototype of Person
Person.prototype = {};
//creating object person2
var person2 = new Person();
Now, person1.constructor
still remains function Person()
, whereas person2.constructor
gives function Object()
.
If I understand correctly, person1.constructor
works by person1.__proto__.constructor
and person1.__proto__
points to Person.prototype
In this case, shouldn't person1.constructor
be function Object()
instead of function Person()
?