import { CommonUtils } from "./common"
|
|
export default class elemIterator{
|
current = 0
|
elemArray = []
|
constructor(current, elemArray){
|
if(CommonUtils.isAllDigits(current) == false) {
|
current = 0
|
}
|
|
if(Array.isArray(elemArray) == false){
|
elemArray = []
|
}
|
|
this.current = Number(current)
|
this.elemArray = elemArray
|
}
|
|
setElemArray(elemArray) {
|
if(Array.isArray(elemArray) == false){
|
throw new TypeError()
|
}
|
this.elemArray = elemArray
|
}
|
|
setElemArrayArgs(...args) {
|
this.elemArray = args
|
}
|
|
moveNext(){
|
this.current++
|
if(this.current == this.elemArray.length){
|
this.current = 0
|
}
|
}
|
|
getCurrentElem(){
|
return this.elemArray[this.current]
|
}
|
|
exec(callback){
|
if(Object.prototype.toString.call(callback) !== '[object Function]'){
|
throw new TypeError()
|
}
|
|
callback.call(null, this.elemArray[this.current])
|
}
|
}
|