倒计时

function Countdown(seconds) {
this._seconds = seconds;
}
Countdown.prototype._step = function() {
console.log(this._seconds);
if (this._seconds > 0) {
this._seconds -= 1;
} else {
clearInterval(this._timer);
}
};
Countdown.prototype.start = function() {
var _this=this;
_this._step();
_this._timer = setInterval(function() {
_this._step();
}, 1000);
};

new Countdown(10).start();
posted @ 2018-11-20 12:13  吾生有涯,而知无涯!  阅读(129)  评论(0编辑  收藏  举报