我想计算单击时调用函数的次数。我有这个目前为止,但它不工作。有人能帮忙吗?如何在调用函数调用次数时调用函数中的闭包
function test(){
var count = (function({
var i = 0;
return function(){
return i += 1;
}
})();
if(count() == 2){
// do this
}
}
调用函数,就像这样:
<select onclick="javascript: test();">
它看起来像count函数没有正确调用。我如何调用该函数并对其执行操作?我想在某些点击次数下执行逻辑。
你似乎很大地过度复杂 - 为什么不把'count'变量放在'test'函数之外,并在被调用时增加它呢? –