Created
May 4, 2014 16:08
-
-
Save yorkie/508a6fecfd237e940c05 to your computer and use it in GitHub Desktop.
it prints 10 not 20, because javascript use static(lexical) scope for function variable
This file contains hidden or 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 x = 10; | |
function foo() { | |
console.log(x); | |
} | |
(function(func) { | |
var x = 20; | |
foo(); | |
})(foo); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment