Created
June 21, 2014 15:35
-
-
Save yardfarmer/74bd86b9d94876953e7d to your computer and use it in GitHub Desktop.
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>闭包是由作用域链引起的</title> | |
</head> | |
<body> | |
在javascript中,作用域是词法化作用域,是方法在定义的时候已经确定的,与调用无关.作用域链创建早于方法调用,得益于此,我们方能使用闭包. | |
</body> | |
</html> |
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 countUpFromZero = function() { | |
var count = 0; | |
return function() { | |
return ++count; | |
}; | |
}(); | |
console.log(countUpFromZero()); | |
console.log(countUpFromZero()); | |
console.log(countUpFromZero()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment