该浏览器不支持canvas

发布订阅模式

var event = {
    _cache: [],
    publish: function(topic, args, scope){
        if(_cache[topic]){
            for(let i = 0; i < _cache[topic].length; i++){
                _cache[topic].apply(scope || this, args || []);
            }
        }
    },
    subscribe:function(topic, callback){
        if(!_cache[topic]){
            _cache[topic] = [];
        }
            _cache[topic].push(callback);
    },
    unsubscribe:function(topic, completly, item){
        if(_cache[topic]){
            if(completly){
                delete _cache[topic];
            }else{
                for(let i = 0; i < _cache.length; i++){
                    if(_cache[topic][i] === item){
                        cache[t].splice(i, 1);
                    }
                }
            }
        }
    };
}

 

posted @ 2020-03-14 13:19  真是啰嗦  阅读(161)  评论(0)    收藏  举报