我知道一些非常基本的东西我缺少。但是找不到有什么问题呢?为什么JavaScript Closure返回undefined
<!DOCTYPE html>
<html>
<body>
<p>A function can access variables defined inside the function:</p>
<button type="button" onclick="alert(makeMyCounter.increment)">Click Me!</button>
<p id="demo"></p>
<script>
var makeMyCounter = function() {
var privateCounter = 0;
return {
increment : function() {
privateCounter += 1;
},
decrement : function() {
privateCounter += -1;
}
}
}();
</script>
</body>
为什么privateCounter返回undefined?但是,当通过浏览器调试时,它被分配1。