Simple question about object constructors in javascript

Hi All,

Please see this code block. The below lets you avoid having to duplicate and type out Person.prototype.(method_name) again and again when defining methods. Instead, I can create a new prototype object, but the side effect is the constructor changes to point back to Object instead of the constructor of Person.

function Person(name) { 
  this.name = name;
}
 
Person.prototype = { 
  constructor: Person, // does not doing this line have any consequences?
  
  sayName: function() {
    console.log(this.name); },
  
  toString: function() {
    return "[Person " + this.name + "]";
  } 
};

What if I don’t assign the constructor back to the object Person (constructor: Person). Is there any consequence of not doing so? Is this just for identity purposes? Thanks!

That constructor property you’re defining won’t have any effect in pure JavaScript, I think you’re getting confused with CoffeeScript