From 701cbb954d75a9d99f15c9cf8cbc4e75b9e678ca Mon Sep 17 00:00:00 2001 From: johnmanong Date: Sun, 30 Aug 2015 14:19:20 -0400 Subject: [PATCH 1/2] [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. From eeed55c1545e0794fbbbf3496cd9f7c865c9eb02 Mon Sep 17 00:00:00 2001 From: johnmanong Date: Mon, 31 Aug 2015 18:29:35 -0400 Subject: [PATCH 2/2] [ong] swap order of new entry --- README.md | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index c41183af..43ce70db 100644 --- a/README.md +++ b/README.md @@ -556,21 +556,7 @@ Other Style Guides } ``` - - [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. + - [7.8](#7.8) Avoid side effects with default parameters. > Why? They are confusing to reason about. @@ -586,6 +572,20 @@ Other Style Guides count(); // 3 ``` + - [7.9](#7.9) Always put default parameters last. + + ```javascript + // bad + function handleThings(opts = {}, name) { + // ... + } + + // good + function handleThings(name, opts = {}) { + // ... + } + ``` + - [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.