return (function(){
timers=null;
if(opts.autopay){
slider.autopay(obj,opts);
}
slider.clearTimers(obj,opts,timers);
})()
autopay:function(obj,opts){
return (function () {
if(opts.times&&opts.autopay){
clearInterval(timers);
timers==null;
if(timers==null){
timers=setInterval(function () {
slider._right(obj,opts);
},opts.times);
}else{
console.log(timers);//这里返回有数值,上面明明清除了定时器
}
}
})();
},
clearTimers:function(obj,opts,timers){
return (function () {
obj.hover(function(){
// opts.autopay=false;
clearInterval(timers);
},function(){
// opts.autopay=true;
slider.autopay(obj,opts);
});
})();
}
修改答案:
timer
记录的是定时器的一个数值,清除时是按照数值清除的,并不会将timers
变为null
你确定进入了
console.log
?应该是永远都进不了吧