代码-JS之闭包
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<script>
//# 闭包
//1.闭包会造成内存不会被释放
//2.闭包使得函数外部可以访问内部的变量
function b(){
var a = 1;
function getA(){
console.log(a++);
}
return getA;
}
var AA = b(); // 返回值getA函数
AA(); // 1
AA(); // 2
AA(); // 3
</script>
</body>
</html>
Copyright [2018] by [羊驼可以吃吗] form [https://www.cnblogs.com/phpisfirst/]