There is a difference between assigning a prototype and assigning a new property to a prototype object.
You declared the Person function as a constructor function, but then you pretty much assign something to your prototype by doing this:
Person.prototype = { toString: function() { return this.firstName + ' ' + this.lastName; } };
This means that you assign a new variable to the toString-function object class in Person.prototype instead of actually adding a new property to it, in which you would have to do it like this:
Person.prototype.toString = function() { return this.firstName + ' ' + this.lastName; }
Which entails that when you actually create a new object that inherits the Person object by calling Object.create , what happens in its implementation, the new object will just be created, and then it will return this new object. which will override the prototype property that you are supposed to have created javascript by doing this Person.prototype assignment earlier in your code.
source share