-
-
Save james-gardner/00271db904052bcf0a0e to your computer and use it in GitHub Desktop.
This file contains 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
console.clear(); | |
var dest = { | |
foo : { | |
b1 : "b1 value", | |
b2 : "b2 value" | |
}, | |
baz : { | |
q1 : "q1 value" | |
}, | |
mofo : "mofo value" | |
}; | |
var src = { | |
foo : { | |
b1: "overwritten b1", | |
b3: "b3 value" | |
}, | |
mofo : "overwritten mofo" | |
}; | |
var assigned = _.clone(dest); | |
_.assign(assigned,src); | |
console.log("assign:", assigned); | |
var merged = _.clone(dest); | |
_.merge(merged,src); | |
console.log("merge:", merged); | |
var defaulted = _.clone(dest); | |
_.defaults(defaulted,src); | |
console.log("defaults:", defaulted); |
This file contains 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
"assign:" | |
[object Object] { | |
baz: [object Object] { | |
q1: "q1 value" | |
}, | |
foo: [object Object] { | |
b1: "overwritten b1", | |
//--> b2 removed | |
b3: "b3 value" | |
}, | |
//--> mofo overwritten | |
mofo: "overwritten mofo" | |
} | |
"merge:" | |
[object Object] { | |
baz: [object Object] { | |
q1: "q1 value" | |
}, | |
foo: [object Object] { | |
b1: "overwritten b1", | |
//--> b2 copied | |
b2: "b2 value", | |
b3: "b3 value" | |
}, | |
//--> mofo overwritten | |
mofo: "overwritten mofo" | |
} | |
"defaults:" | |
[object Object] { | |
baz: [object Object] { | |
q1: "q1 value" | |
}, | |
foo: [object Object] { | |
b1: "overwritten b1", | |
//--> b2 copied | |
b2: "b2 value", | |
b3: "b3 value" | |
}, | |
//--> mofo NOT overwritten | |
mofo: "mofo value" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment