From ac186ae925590327a5be73e2bfe3a272c88b3e15 Mon Sep 17 00:00:00 2001 From: Hollie Kay Date: Wed, 24 Aug 2016 10:36:18 +0100 Subject: [PATCH 1/3] Add stuff about strict mode --- languages/javascript.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/languages/javascript.md b/languages/javascript.md index 3d3a4400..6508fdfd 100644 --- a/languages/javascript.md +++ b/languages/javascript.md @@ -11,6 +11,7 @@ Projects should use both [JSHint] and [ESLint] to enforce these rules. - [Write modules over monoliths](#modules-over-monoliths) - [KISS](#keep-it-simple) - [Performant Code](#performant-code) + - [Error handling](#error-handling) - [Code Style](#code-style) - [Indentation](#indentation) - [White Space](#white-space) @@ -123,6 +124,12 @@ We should always try to write fast code, but not if it makes the code difficult If you're writing a small library with a single simple purpose, and you really _really_ need to do it, then it makes sense; in a project with more than one contributor, there's frequently more "cost" than "benefit". +### Error handling + +You should assume that your code will fail, and take steps to handle those failures. + +Where [ES5 and above is available and strict mode is implemented](http://kangax.github.io/compat-table/es5/), use strict mode: `'use strict';` + Code Style --------- From 24dc84fe5e3041d46c784361bcb84ea5c438c50c Mon Sep 17 00:00:00 2001 From: Hollie Kay Date: Wed, 24 Aug 2016 13:07:16 +0100 Subject: [PATCH 2/3] work in existing work from Nature playbook --- languages/javascript.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/languages/javascript.md b/languages/javascript.md index 6508fdfd..9714046b 100644 --- a/languages/javascript.md +++ b/languages/javascript.md @@ -128,7 +128,12 @@ If you're writing a small library with a single simple purpose, and you really _ You should assume that your code will fail, and take steps to handle those failures. -Where [ES5 and above is available and strict mode is implemented](http://kangax.github.io/compat-table/es5/), use strict mode: `'use strict';` +Where [ES5 and above is available and strict mode is implemented](http://kangax.github.io/compat-table/es5/), use strict mode: `'use strict';` This causes JavaScript to error early rather than allow malformed or incorrect code to run. + +In Node.js, you can add `'use strict';` to the top of each of your source files. + +In-browser you should not add your `'use strict';` to the top of the file; instead you should add it to either the file's IIFE or each defined function if an IIFE isn't present. This is because global strict mode in browsers can cause issues with third-party code. + Code Style --------- From 56a03aa71575ac36e26949e55f78809279e05c2a Mon Sep 17 00:00:00 2001 From: Hollie Kay Date: Wed, 24 Aug 2016 13:09:49 +0100 Subject: [PATCH 3/3] put the IIFE link back :/ --- languages/javascript.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/languages/javascript.md b/languages/javascript.md index 9714046b..ad3259d6 100644 --- a/languages/javascript.md +++ b/languages/javascript.md @@ -132,7 +132,7 @@ Where [ES5 and above is available and strict mode is implemented](http://kangax. In Node.js, you can add `'use strict';` to the top of each of your source files. -In-browser you should not add your `'use strict';` to the top of the file; instead you should add it to either the file's IIFE or each defined function if an IIFE isn't present. This is because global strict mode in browsers can cause issues with third-party code. +In-browser you should not add your `'use strict';` to the top of the file; instead you should add it to either the file's [IIFE](http://benalman.com/news/2010/11/immediately-invoked-function-expression/) or each defined function if an IIFE isn't present. This is because global strict mode in browsers can cause issues with third-party code. Code Style