JS 闭包得到一个递增的值
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<button id="mybtn" >点击</button>
</body>
<script>
function getNumFunction(){
var a=0;
return function(){
a+=1;
console.log(a);
}
}
var fun= getNumFunction();
document.getElementById('mybtn').onclick = function(){
fun();
}
</script>
</html>