zrg
7 小时以前 359befaa90ca7037153f77ee38f03c6b41306e9a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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])
    }
}