/** *seconds int 倒计时的总秒数 *func function 每一秒触发的回调 */ function timeWalker(seconds, func){ this.tid=0; this.start = function(){ this.tid = setInterval((function(sec, obj){ return function(){ typeof func ==='function' && func(sec); if(sec<=1) { clearInterval(obj.tid); }else{ --sec; } }; })(seconds, this), 1000); }; this.stop = function(){ clearInterval(this.tid); } this.start(); } 使用方法: new timeWalker(50, function(sec){console.log(sec);});