Last active
May 23, 2016 03:17
-
-
Save namikingsoft/1371fdc32d7e897919cd8fce37a5112c to your computer and use it in GitHub Desktop.
Object.assign vs Object rest spread
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
{ | |
let options = { | |
key1: "val1", | |
}; | |
const optionsDefault = { | |
key1: "default-val1", | |
key2: "default-val2", | |
}; | |
// object rest spread on es7 | |
options = {...optionsDefault, ...options}; | |
// test | |
assert.deepEqual(options, { | |
key1: "val1", | |
key2: "default-val2", | |
}); | |
} | |
{ | |
let options = { | |
key1: "val1", | |
}; | |
const optionsDefault = { | |
key1: "default-val1", | |
key2: "default-val2", | |
}; | |
// object asign | |
options = Object.assign({}, optionsDefault, options); | |
// test | |
assert.deepEqual(options, { | |
key1: "val1", | |
key2: "default-val2", | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment