Created
February 11, 2012 03:20
-
-
Save kassy-kz/1795693 to your computer and use it in GitHub Desktop.
closure1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var outerFunc = function() { | |
var tmp = "hoge"; | |
var innerFunc = function() { | |
document.write(tmp); | |
return tmp; | |
}; | |
return innerFunc; | |
}; | |
var myFunc = outerFunc(); // myFuncにはinnerFunc相当の | |
var tmp = "aefaffaf"; | |
var myFunc2 = function(){ | |
document.write(tmp); | |
return tmp; | |
}; | |
myFunc(); // hoge が表示される | |
myFunc2(); // aefaffaf が表示される |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment