From 209f944c579e637912964d8efa1d9052b78b9e4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89des=20Bal=C3=A1zs?= Date: Sat, 21 Jan 2017 02:37:44 +0000 Subject: [PATCH] Changed Function arguments section to include destructuring --- README.md | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 97a0a464..653db4ff 100644 --- a/README.md +++ b/README.md @@ -212,6 +212,17 @@ Since JavaScript allows us to make objects on the fly, without a lot of class boilerplate, you can use an object if you are finding yourself needing a lot of arguments. +To make it more obvious what properties does the function expect, use the es6 +destructuring syntax. This has a couple of advantages: + +1. When someone looks at the function signature, it's immediately clear what +properties are used. +2. Since the function doesn't have the reference to the actual argument, the +user of the function can be sure that no other properties are used by anything +down the call chain. +3. Linters (like eslint) can warn you about unused properties, while this would +be impossible without destructuring. + **Bad:** ```javascript function createMenu(title, body, buttonText, cancellable) { @@ -221,7 +232,7 @@ function createMenu(title, body, buttonText, cancellable) { **Good:** ```javascript -function createMenu(config) { +function createMenu({ title, body, buttonText, cancellable }) { // ... }