mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2024-12-23 17:41:41 +00:00
fix immediately-executing function
This commit is contained in:
parent
293c65c286
commit
f5023cc9b3
@ -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
|
// This has led to a common pattern of "immediately-executing anonymous
|
||||||
// functions", which prevent temporary variables from leaking into the global
|
// functions", which prevent temporary variables from leaking into the global
|
||||||
// scope.
|
// scope.
|
||||||
function(){
|
(function(){
|
||||||
var temporary = 5
|
var temporary = 5
|
||||||
// We can access the global scope by assiging to the 'global object', which
|
// 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
|
// in a web browser is always 'window'. The global object may have a
|
||||||
@ -249,7 +249,7 @@ function(){
|
|||||||
window.permanent = 10
|
window.permanent = 10
|
||||||
// Or, as previously mentioned, we can just leave the var keyword off.
|
// Or, as previously mentioned, we can just leave the var keyword off.
|
||||||
permanent2 = 15
|
permanent2 = 15
|
||||||
}()
|
})()
|
||||||
temporary // raises ReferenceError
|
temporary // raises ReferenceError
|
||||||
permanent // = 10
|
permanent // = 10
|
||||||
permanent2 // = 15
|
permanent2 // = 15
|
||||||
|
Loading…
Reference in New Issue
Block a user