Apply new format to snippets and template
This commit is contained in:
@ -5,7 +5,7 @@ tags: object,intermediate
|
||||
|
||||
Assigns default values for all properties in an object that are `undefined`.
|
||||
|
||||
Use `Object.assign()` to create a new empty object and copy the original one to maintain key order, use `Array.prototype.reverse()` and the spread operator `...` to combine the default values from left to right, finally use `obj` again to overwrite properties that originally had a value.
|
||||
- Use `Object.assign()` to create a new empty object and copy the original one to maintain key order, use `Array.prototype.reverse()` and the spread operator `...` to combine the default values from left to right, finally use `obj` again to overwrite properties that originally had a value.
|
||||
|
||||
```js
|
||||
const defaults = (obj, ...defs) => Object.assign({}, obj, ...defs.reverse(), obj);
|
||||
|
||||
Reference in New Issue
Block a user