From 20f44481182dffec94fd14c93f1ae9cc21a59ab9 Mon Sep 17 00:00:00 2001 From: Balazs Nadasdi Date: Wed, 9 Oct 2013 07:33:27 +0200 Subject: [PATCH 1/2] IIFE changed to Crockford's prefered format. The first parenthesis is a marker for an IIFE and there is no need to call the function only for let JavaScript know it will be called immediately. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 149df336c2..b9e25836e7 100644 --- a/README.md +++ b/README.md @@ -279,7 +279,7 @@ // immediately-invoked function expression (IIFE) (function() { console.log('Welcome to the Internet. Please follow me.'); - })(); + }()); ``` - Never declare a function in a non-function block (if, while, etc). Assign the function to a variable instead. Browsers will allow you to do it, but they all interpret it differently, which is bad news bears. From 15b1952666184764e316469604050cee80f8f1c0 Mon Sep 17 00:00:00 2001 From: Balazs Nadasdi Date: Wed, 9 Oct 2013 07:40:08 +0200 Subject: [PATCH 2/2] more IIFE --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index b9e25836e7..a9df7a75bb 100644 --- a/README.md +++ b/README.md @@ -775,14 +775,14 @@ // bad (function(global) { // ...stuff... - })(this); + }(this)); ``` ```javascript // good (function(global) { // ...stuff... - })(this); + }(this)); ``` @@ -891,19 +891,19 @@ (function() { var name = 'Skywalker' return name - })() + }()) // good (function() { var name = 'Skywalker'; return name; - })(); + }()); // good ;(function() { var name = 'Skywalker'; return name; - })(); + }()); ``` **[[⬆]](#TOC)**