Last active
December 18, 2017 17:29
-
-
Save jdmichaud/81e4f6fc6f7c0f82877f069d7928c094 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// npm install --save lodash @types/lodash | |
import * as lodash from 'lodash'; | |
class A { | |
public property: number; | |
} | |
class B { | |
public a: A; | |
} | |
class C { | |
constructor(object: C) { | |
(Object as any).assign(this, object); | |
} | |
public name: string; | |
public b: B; | |
} | |
const c = new C(JSON.parse('{ "name": "Billy", "b": { "a": { "property": 42 } } }')); | |
const b = c.b; | |
console.log(JSON.stringify(c)); // {"name":"Billy","b":{"a":{"property":42}}} | |
lodash.merge(c, JSON.parse('{ "b": { "a": { "property": 666 } } }')); | |
console.log(JSON.stringify(c)); // {"name":"Billy","b":{"a":{"property":666}}} | |
console.log(b === c.b); // true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment