From 600ee35644ca3ae998b321656a929b3774d2bbb0 Mon Sep 17 00:00:00 2001 From: Isabelle Viktoria Maciohsek Date: Mon, 19 Oct 2020 18:51:24 +0300 Subject: [PATCH] Update defaults --- snippets/defaults.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/snippets/defaults.md b/snippets/defaults.md index f0fe34106..c2ec18710 100644 --- a/snippets/defaults.md +++ b/snippets/defaults.md @@ -5,7 +5,9 @@ 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); @@ -13,4 +15,4 @@ const defaults = (obj, ...defs) => Object.assign({}, obj, ...defs.reverse(), obj ```js defaults({ a: 1 }, { b: 2 }, { b: 6 }, { a: 3 }); // { a: 1, b: 2 } -``` \ No newline at end of file +```