export default class Loop {
props: {
onLoop(item): Function;
}
loopBody = [];
point = 0;
create(body) {
this.loopBody = body;
if (this.props.onLoop) {
this.props.onLoop(this.loopBody[this.point]);
}
}
next() {
this.point += 1;
if (this.point == this.loopBody.length) {
this.point = 0;
}
if (this.props.onLoop) {
this.props.onLoop(this.loopBody[this.point]);
}
}
}
我写了一个这样的类。如下初始化这个类。可以通过let l=new Loop();但是如何使用到onLoop(item)这个属性?