gpt4 book ai didi

javascript - 为什么这个值在 JavaScript 中是 3?

转载 作者:行者123 更新时间:2023-11-30 07:20:52 25 4
gpt4 key购买 nike

<分区>

我认为下面的代码应该显示 4,为什么它会产生 3?

function arithFunc() {
var n = 0;
return {
plusOP: function() {
return n++;
},
minusOP: function() {
return n--;
}

};
}

var aTest = arithFunc(),
bTest = arithFunc();

document.getElementById("demo").innerHTML = aTest.plusOP();
document.getElementById("demo").innerHTML = aTest.plusOP();
document.getElementById("demo").innerHTML = bTest.minusOP();
document.getElementById("demo").innerHTML = aTest.plusOP();
document.getElementById("demo").innerHTML = bTest.minusOP();
document.getElementById("demo").innerHTML = aTest.plusOP();
<p id="demo"></p>

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com