Reputation: 3
Is it possible to send a parameter to a prototype to set new properties of an object? for example:
function person(first, last, age, eyecolor) {
this.firstName = first;
this.lastName = last;
this.age = age;
this.eyeColor = eyecolor;
}
person.prototype = function(color) {
this.hair_color = color;
};
This may not have been implemented correctly, but my question is still the same. I am trying to make sure I understand prototypes so maybe I am missing a fundamental idea about them. It seems that everywhere I look prototypes are used to set defined variables as opposed to one that is input such as this
person.prototype = function() {
this.hair_color = "brown";
};
Upvotes: 0
Views: 51
Reputation: 8599
Prototype allows you add new properties and correct way of doing that will be:
person.prototype.hair_color = "brown";
Upvotes: 1