Created
June 1, 2012 20:57
-
-
Save dherman/2855099 to your computer and use it in GitHub Desktop.
deep vs shallow update
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
var obj = { | |
a: { | |
foo: 1, | |
bar: 2 | |
}, | |
b: { | |
quux: 3 | |
}, | |
c: 4 | |
}; | |
obj.{ | |
// nested update | |
a.{ | |
baz = 5 | |
}; | |
// replace | |
b = { | |
mumble: 6 | |
}; | |
d = 5; | |
}; | |
obj.a.foo === 1 && | |
obj.a.bar === 2 && | |
obj.a.baz === 5 && | |
!("quux" in obj.b) && | |
obj.b.mumble === 6 |
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
var obj = { | |
a: { | |
foo: 1, | |
bar: 2 | |
}, | |
b: { | |
quux: 3 | |
}, | |
c: 4 | |
}; | |
obj.={ | |
// nested update | |
a.={ | |
baz: 5 | |
}, | |
// replace | |
b: { | |
mumble: 6 | |
} | |
d: 5, | |
}; | |
obj.a.foo === 1 && | |
obj.a.bar === 2 && | |
obj.a.baz === 5 && | |
!("quux" in obj.b) && | |
obj.b.mumble === 6 |
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
var obj = { | |
a: { | |
foo: 1, | |
bar: 2 | |
}, | |
b: { | |
quux: 3 | |
}, | |
c: 4 | |
}; | |
obj.{ | |
// nested update | |
a.{ | |
baz: 5 | |
}, | |
// replace | |
b: { | |
mumble: 6 | |
} | |
d: 5, | |
}; | |
obj.a.foo === 1 && | |
obj.a.bar === 2 && | |
obj.a.baz === 5 && | |
!("quux" in obj.b) && | |
obj.b.mumble === 6 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment