Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>闭包是由作用域链引起的</title>
</head>
<body>
在javascript中,作用域是词法化作用域,是方法在定义的时候已经确定的,与调用无关.作用域链创建早于方法调用,得益于此,我们方能使用闭包.
</body>
</html>
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
You can’t perform that action at this time.