代码
<!doctype html>
<html>
<head>
<title>JavaScript闭包</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<meta http-equiv="Pragma" content="no-cache"/>
</head>
<body>
<h1>JavaScript闭包</h1>
</body>
<script src="http://libs.baidu.com/jquery/2.1.4/jquery.min.js"></script>
<script>
console.log(a);
function a() {
var b = function () {
console.log(100);
return 300;
}
return b;
}
console.log(a);
var c = a();
console.log(c);
console.log(a()());
var stu = {
name: "xiaoming",
age: 18,
study: function () {
console.log('正在学习');
}
}
var add = (function () {
var counter = 0;
return function () {
return counter += 1;
}
})();
add();
add();
var re = add();
console.log(re);
/*
* var a
* function a(){
*
* }
* a=10
* */
</script>
</html>