From 132b1dd2cc277d300067ec591fcb462d2146d685 Mon Sep 17 00:00:00 2001 From: marlon Felipe Passos Date: Thu, 4 Aug 2022 23:02:47 -0300 Subject: [PATCH] =?UTF-8?q?feat(Defina=20(set)=20objetos=20...):=20adicion?= =?UTF-8?q?ando=20um=20exemplo=20de=20desestrura=C3=A7=C3=A3o?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/README.md b/README.md index 1a0fb2e..a4f49a1 100644 --- a/README.md +++ b/README.md @@ -451,6 +451,38 @@ function createMenu(config) { } createMenu(menuConfig); + + +// Ou usar o conceito de desestruturação vindo no ES6 +// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment + +const DEFAULT_CONFIG_MENU = { + title: 'Foo', + body: 'Bar', + buttonText: 'Baz', + cancellable: true +} + +const menuConfig = { + title: 'Order', + // Usuário não incluiu a chave 'body' + buttonText: 'Send', + cancellable: true +}; + +function createMenu(config) { + config = { + ...DEFAULT_CONFIG_MENU, + ...config + }; + + // configuração agora é: {title: "Order", body: "Bar", buttonText: "Send", cancellable: true} + // ... +} + +createMenu(menuConfig); + + ``` **[⬆ voltar ao topo](#Índice)**