我正在关注本教程:https : //www.youtube.com/watch?v=1JsJx1x35c0
但是,当我运行此代码时,它给了我一个错误
var counter = (function(){
var privateCounter = 0
function changeBy(val){
privateCounter += val
}
return {
increment: function(){
changeBy(1)
},
decrement: function(){
changeBy(-1)
},
value: function(){
return privateCounter
}
}
})
console.log(counter.value())
counter.increment()
counter.increment()
console.log(counter.value())
counter.decrement()
console.log(counter.value())
我明白了
未捕获的类型错误:counter.value 不是函数
这有什么解释?为什么它认为counter.value()不是一个函数?
慕莱坞森
ibeautiful
明月笑刀无情
随时随地看视频慕课网APP
相关分类