<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>闭包</title>
</head>
<script>
//闭包函数
function add(){
let num = 0;
return function(){
return ++ num
}
}
//普通返回函数
function commonAdd(){
let num = 0;
return ++ num
}
let add1 = add();
let add2 = add();
console.log(add1()) //1
console.log(add1()) //2 具有累计效果
console.log(add2()) //1 add1和add2不在一个内存区
let add3 = commonAdd();
let add4 = commonAdd();
console.log(add3) //1
console.log(add3) //1 都是独立运行
console.log(add4) //1
</script>
<body>
</body>
</html>
调用方式不一样。闭包应该叫 函数的函数(从调用貌似可以这样叫,哈哈哈)