A Pen by Andrew Kirchmyer on CodePen.
Created
November 17, 2013 05:04
-
-
Save akirchmyer/7509506 to your computer and use it in GitHub Desktop.
A Pen by Andrew Kirchmyer.
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
| // three objects with nested data | |
| var app = { | |
| config: {} | |
| }; | |
| app.app_config = { | |
| one: 1, | |
| two: 1, | |
| prefs: { | |
| one: 1, | |
| two: 1, | |
| thisShouldNotBeGone: true | |
| } | |
| }; | |
| app.client_config = { | |
| two: 2, | |
| three: 2, | |
| prefs: { | |
| two: 2 | |
| }, | |
| overrides: { | |
| thisShouldBeGone: true, | |
| three: 2 | |
| } | |
| }; | |
| app.user_config = { | |
| three: 3, | |
| overrides: { | |
| three: 3 | |
| } | |
| }; | |
| // Pass in true as the first param to deeply extend. Object property values will be merged between each config with overrides occurring only when two objects have the same property value. | |
| $.extend(true, app.config, app.app_config, app.client_config); | |
| // Here we use a shallow copy. Objects in app.config will be completely replaced by objects in app.user_config rather than being merged. | |
| $.extend(app.config, app.user_config); | |
| console.log(app.config); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment