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");


转载于:https://my.oschina.net/zhouz/blog/213162

猜你喜欢

转载自blog.csdn.net/weixin_33948416/article/details/91728511