From f5023cc9b35be5d1986a76ce1d6f44979a766afb Mon Sep 17 00:00:00 2001 From: greybird Date: Mon, 5 Aug 2013 17:22:53 +0400 Subject: [PATCH] fix immediately-executing function --- javascript.html.markdown | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/javascript.html.markdown b/javascript.html.markdown index 9cc7617d..cc279b9a 100644 --- a/javascript.html.markdown +++ b/javascript.html.markdown @@ -241,7 +241,7 @@ i // = 5 - not undefined as you'd expect in a block-scoped language // This has led to a common pattern of "immediately-executing anonymous // functions", which prevent temporary variables from leaking into the global // scope. -function(){ +(function(){ var temporary = 5 // We can access the global scope by assiging to the 'global object', which // in a web browser is always 'window'. The global object may have a @@ -249,7 +249,7 @@ function(){ window.permanent = 10 // Or, as previously mentioned, we can just leave the var keyword off. permanent2 = 15 -}() +})() temporary // raises ReferenceError permanent // = 10 permanent2 // = 15