Skip to content

Instantly share code, notes, and snippets.

@namikingsoft
Last active May 23, 2016 03:17
Show Gist options
  • Save namikingsoft/1371fdc32d7e897919cd8fce37a5112c to your computer and use it in GitHub Desktop.
Save namikingsoft/1371fdc32d7e897919cd8fce37a5112c to your computer and use it in GitHub Desktop.
Object.assign vs Object rest spread
{
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