1

I wonder that is there easy way to set this properties with constructor parameters like using spread operator or another way?

this is clasical way of setting props of this:

constructor(id=0, name='', surname='') {
  this.Id = id;
  this.Name = name;
  this.Surname = surname;
}

I am looking for another way to set this props in one line :)

0

1 Answer 1

5

You can use Object#assign to merge an object created from the params to this:

constructor(id=0, name='', surname='') {
  Object.assign(this, { id, name, surname });
}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.