I'm looking to create a method for an object to update only the properties that are passed.
for example
function Car () {
this.color = 'yellow'
this.brand = 'bmw'
this.key = 0
this.update = function (o) {
this.key++
// maybe Object.assign(this, o) somehow ??
}
}
If I do Car.update({color:'red'}) I want to update the object but not overwrite the brand. I want to use something like Object.assign(this, o) but not sure how to assign it. Do I need to create a prototype? Car.prototype.update = ?
Object.assign? It will updatethisif you pass that as first argument. No need to assign anything more.new Car()first