From 102c55aa17fb7a906067ac3a6f3a2d20dadf05d2 Mon Sep 17 00:00:00 2001 From: Emad Motameni Date: Sun, 2 Mar 2025 14:27:15 +0330 Subject: [PATCH] fix(README.md): Set default objects with spread operator --- README.md | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index f1159781..6c0b4dcb 100644 --- a/README.md +++ b/README.md @@ -509,7 +509,7 @@ function showEmployeeList(employees) { **[⬆ back to top](#table-of-contents)** -### Set default objects with Object.assign +### Set default objects with Spread Operator **Bad:** @@ -543,15 +543,13 @@ const menuConfig = { }; function createMenu(config) { - let finalConfig = Object.assign( - { - title: "Foo", - body: "Bar", - buttonText: "Baz", - cancellable: true - }, - config - ); + let finalConfig = { + title: "Foo", + body: "Bar", + buttonText: "Baz", + cancellable: true, + ...config + }; return finalConfig // config now equals: {title: "Order", body: "Bar", buttonText: "Send", cancellable: true} // ...