I have a prototype
class Animal() {
constructor(name, weight) {
this.name = name
this.weight = weight
}
}
and some coming object, which contains these properties plus something else
const obj = {
name: "name",
weight: 5,
someRedundantProp: "bla"
}
I really enjoy JS mapping with Object.assign which would generically create an object for me with all properties, but here I want to fill this new object only with essential fields. Surely, I can map this object like
new Animal(obj.name, obj.weight)
but if at some point I would introduce new properties I will have to change code here, what I don't want to.
Is there some better way?
constructor(obj) { this.name = obj.name; ...