javascript 延时执行函数

延时执行函数,貌似有些多此一举, 也许还是有点用 记在这儿

var test = {
    delay : function(lifetime){
            var data;
            setTimeout(function(){
                    for (name in test.methods) {
                        eval("data = test.methods."+ name +"();");
                    }
                }, lifetime);
            return this;
        },
    methods : {},
    register : function(name, callback){
            eval("this.methods."+ name +" = callback;");
            return this;
        },
    output1 : function(message){
            this.register("output1", function(){ alert(message); });
            return this;
        },
    output2 : function(message){
            this.register("output2", function(){ alert(message); });
            return this;
        }
}
test.delay(3000).output1("aaa").output2("bbb");


你可能感兴趣的:(settimeout,延时执行)