1.0.0 • Published 5 years ago
@writetome51/get-object-copy-modified v1.0.0
getObjectCopyModified( object, changes): object
Makes a copy of object
, merges changes
into it and returns the copy.
Neither of the two arguments get modified. Prototype chain stays intact.
Examples
let obj = {prop1: 10, prop2: 20, prop3: 30};
let changes = {prop1: 100, prop2: 200, prop4: 1000};
getObjectCopyModified(obj, changes);
// --> {prop1: 100, prop2: 200, prop3: 30, prop4: 1000}
obj = {prop1: 10, prop2: 20};
changes = {
prop1: 100,
prop3: function () {
return this.prop1 + this.prop2;
}
};
let newObj = getObjectCopyModified(obj, changes);
console.log(newObj.prop3());
// console: '120'
Installation
npm i @writetome51/get-object-copy-modified
Loading
// If using TypeScript:
import {getObjectCopyModified} from '@writetome51/get-object-copy-modified';
// If using ES5 JavaScript:
var getObjectCopyModified =
require('@writetome51/get-object-copy-modified').getObjectCopyModified;
1.0.0
5 years ago