像设置一个随机定时器,就是每次执行之后随机时间间隔定时执行。类似于setTimeOut
:
// my component
act() {
// dosomething
let delay = Math.floor(Math.random()*3) + 2;
this.scheduleOnce(this.act, delay);
},
start() {
this.act();
}
结果act()
只运行2次
schedule()
无法嵌套调用?
ps
scheduleOnce()
是对schedule(fn, 0,0,delay)
的封装?
尝试过schedule(act, delay, 0, 0)
,结果是一样的