0

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";
};

1 Answer 1

1

Prototype allows you add new properties and correct way of doing that will be:

person.prototype.hair_color = "brown";
Sign up to request clarification or add additional context in comments.

1 Comment

I think it is important to mention that now all person have brown hair.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.