题解 | #添加元素#
计时器
http://www.nowcoder.com/practice/72c661d926494bd8a50608506915268c
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
}