打印出来是什么?
function counter(){
var n=0;
return{
count:function(){return n++;},
reset:function(){n=0;}
};
}
var c=counter();
var d=counter();
console.log(c.count);
书上写的是0
我这边打印出来结果怎么是function();
------解决方案--------------------
function counter(n){
return{
'get count':function(){return n++;},
'set count':function(m){if(m>=n){n=m}else {throw Error("error");}}
}
}
var c = counter(1000);
console.log(c['get count']());