copy-object
Copy, clone and merge, full or partially, javascript objects.
Installation
Easily via npm.
npm install copy-object
Usage
var result =
destinationObject
is, if not provided, an empty Object
keyList
is an Array
of keys to copy, if not provided, all keys will be copied.
Examples
Behavior
var copyObject = sourceObj = a: 1 b: 2 c: 3 ; /** * Source object is not bitwise equally it's copy */ === sourceObj// false /** * Previously defined objects will equal bitwise after copying it. */var destObj = {}; === destObj// true destObj// { a: 1, b: 2, c: 3} /** * Copies only selected keys. */// { a: 1 } /** * Copies only selected keys. */var existingObject = d: 4 e: 5 // { a: 1, b: 2, c: 3, d: 4, e: 5 }
Some real life examples:
var EventEmitter = EventEmitter; /** * Example class, inherits EventEmitter */ { thisa = 1; thisb = 2; thisc = 3; this_private = 4; this_someOther = 5;} // Inherit EventEmitter's prototypeMyClassprototype = ; /** * Returns object with selected attributes. */MyClassprototype { return ;};