function count(start, end) {
obj.timer = setInterval(() => {
console.log(start++);
if (start == end + 1) {
clearInterval(obj.timer)
}
}, 100)
return obj
}
console.log(start++);
// 选择题做多了,就想到这样写了,怕清除不到 timer o(╥﹏╥)o
var obj = { timer: null, cancel: function () { clearInterval(this.timer) } }obj.timer = setInterval(() => {
console.log(start++);
if (start == end + 1) {
clearInterval(obj.timer)
}
}, 100)
return obj
}