javascript 构造函数方式 对象

来源:互联网 发布:linux cpu使用率过高 编辑:程序博客网 时间:2024/04/30 09:40
/**
* 构造函数方式 对象
*/
function TimerUitls() {
    this.setParam = setParam;
    this.runTimer = runTimer;
    this.runCall = runCall;
    this.isState =  isState;
    this.init = init;
    var counter = 0;
    var max = 0;
    var time = 100;
    var states = "uninitialized";
    var oDom = null;
    function setParam(p_max, p_time) {
        max = p_max;
        counter = p_max+1;
        time = p_time;
    }
    function runTimer() {
        counter++;
        if (counter <= max) {
setTimeout(runTimer, time);
        } else {
            var state = isState(); //
            if (state == "complete") {
                runCall();
            } else {
                counter = 0;
                runTimer();
            }
        }
    }

    function isState(){
        var o_state ="";
        if (typeof(oDom) == "object") {
              o_state = oDom.document.readyState;
        }
        return o_state;
    }
    function  runCall(){

    }
    function init(p_dom,p_max,p_time) {
         oDom = p_dom;
         setParam(p_max, p_time);
         runTimer();
    }
}
原创粉丝点击