From 701cbb954d75a9d99f15c9cf8cbc4e75b9e678ca Mon Sep 17 00:00:00 2001 From: johnmanong Date: Sun, 30 Aug 2015 14:19:20 -0400 Subject: [PATCH] [ong] Default parameters go last. --- README.md | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 73f3dbfd..c41183af 100644 --- a/README.md +++ b/README.md @@ -556,7 +556,21 @@ Other Style Guides } ``` - - [7.8](#7.8) Avoid side effects with default parameters + - [7.8](#7.8) Always put default parameters last. + + ```javascript + // bad + function handleThings(opts = {}, name) { + // ... + } + + // good + function handleThings(name, opts = {}) { + // ... + } + ``` + + - [7.9](#7.9) Avoid side effects with default parameters. > Why? They are confusing to reason about. @@ -572,7 +586,7 @@ Other Style Guides count(); // 3 ``` -- [7.9](#7.9) Never use the Function constructor to create a new function. +- [7.10](#7.10) Never use the Function constructor to create a new function. > Why? Creating a function in this way evaluates a string similarly to eval(), which opens vulnerabilities.