@writetome51/modify-object
v2.0.1
Published
Function merges one object into another
Downloads
10
Maintainers
Readme
modifyObject( objectToModify, changes: object): void
changes
are merged into objectToModify
.changes
is not modified. objectToModify
keeps its own prototype chain.
Examples
let objToModify = {prop1: 10, prop2: 20};
let changes = {prop1: 100, prop3: 30};
modifyObject(objToModify, changes);
console.log(objToModify);
// { prop1: 100, prop2: 20, prop3: 30 }
changes = {
getSum: function () {
return this.prop1 + this.prop2 + this.prop3;
}
};
modifyObject(objToModify, changes);
console.log(objToModify.getSum());
// 150
Installation
npm i @writetome51/modify-object
Loading
import {modifyObject} from '@writetome51/modify-object';