Subpub 订阅/发布
var Pubsub = (function (window) {
window.handlers = {};
var o = {
pub: function () {
var args = Array.prototype.slice.call(arguments,0),
event = args.shift();
var cbs = handlers[event];
if (cbs) {
for (var i = 0; i < cbs.length; i++) {
cbs[i].apply(cbs[i].args);
}
}
},
sub: function (event, callback) {
if (!handlers[event]) {
handlers[event] = [];
}
handlers[event].push(callback);
}
};
o.publish = o.pub;
o.subscribe = o.sub;
return o;
})(window);
Pubsub.sub("click", function () {
console.log('1 click');
})
Pubsub.sub("click", function () {
console.log('2 click');
})
Subpub 订阅/发布的更多相关文章
- ServiceStack.Redis订阅发布服务的调用(Z)
1.Redis订阅发布介绍Redis订阅发布是一种消息通信模式:发布者(publisher)发送消息,订阅者(Subscriber)接受消息.类似于设计模式中的观察者模式.发布者和订阅者之间使用频 ...
- ServiceStack.Redis订阅发布服务的调用
1.Redis订阅发布介绍 Redis订阅发布是一种消息通信模式:发布者(publisher)发送消息,订阅者(Subscriber)接受消息.类似于设计模式中的观察者模式. 发布者和订阅者之间使用频 ...
- Sql订阅发布注意事项
1.做订阅发布的2台Sql服务器最好要版本一致,不能出现类似如下情况: Sql2008 R2[发布] - Sql2008[订阅]: Sql2008 R2[发布] - Sql2012[订阅] 2.订阅发 ...
- Redis系列(三)—— 订阅/发布
Redis 订阅/发布 参考:http://www.cnblogs.com/mushroom/p/4470006.html,http://www.tuicool.com/articles/ABry2a ...
- 2016022611 - redis订阅发布命令集合
redis消息订阅发布命令 参考地址:http://www.yiibai.com/redis/redis_pub_sub.html 消息发送者发送消息,通过redis的channal,消息接收者获取消 ...
- Publisher/Subscriber 订阅-发布模式
Publisher/Subscriber 订阅-发布模式 本博后续将陆续整理这些年做的一些预研demo,及一些前沿技术的研究,与大家共研技术,共同进步. 关于发布订阅有很多种实现方式,下面主要介绍WC ...
- 设计模式---订阅发布模式(Subscribe/Publish)
设计模式---订阅发布模式(Subscribe/Publish) 订阅发布模式定义了一种一对多的依赖关系,让多个订阅者对象同时监听某一个主题对象.这个主题对象在自身状态变化时,会通知所有订阅者对象,使 ...
- 基于Http协议订阅发布系统设计
基于Http协议订阅发布系统设计 --物联网系统架构设计 1,订阅发布(subscriber-publisher) 订阅发布模式最典型的应用场景就是消息系统的设计.在消息系统的架构中 ...
- Redis 订阅发布 - Jedis实现
Redis 订阅发布 - Jedis实现 我想到使用Redis的订阅发布模式是用来解决推送问题的-. 对于概念性的叙述,多多少少还是要提一下的: 什么是Redis发布订阅?Redis发布订阅是一种 ...
随机推荐
- spring,hibernate配置事务 beans.xml
beans.xml <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="htt ...
- Lorenzo Von Matterhorn
Lorenzo Von Matterhorn Barney lives in NYC. NYC has infinite number of intersections numbered with p ...
- 我的android学习脚步----------- Button 和监听器setonclicklistener
最基本的学习,设置一个按钮并监听实现实时时刻显示 首先XML布局,在layout中的 activity_main.xml中拖一个Button按钮到相应位置 然后在xml文件中做修改 <Rela ...
- push控制器 卡顿
代码: RecommendController *rec = [[RecommendController alloc]init]; [self.navigationController pushVie ...
- Android PopupWindow的使用技巧(转)
Android PopupWindow的使用技巧 PopupWindow是Android上自定义弹出窗口,使用起来很方便. PopupWindow的构造函数为 public PopupWindow(V ...
- 绑定网关mac,防arp攻击
netsh i i show innetsh -c i i add neighbors 16 192.168.1.1 08-57-00-51-19-7c
- 转:使用WITH AS提高性能简化嵌套SQL
使用WITH AS提高性能简化嵌套SQL 一.WITH AS的含义 WITH AS短语,也叫做子查询部分(subquery factoring),可以让你做很多事情,定义一个SQL片断,该SQL片 ...
- View如何设置16进制颜色值
View.setBackgroundColor(Color.parseColor("#F3733F"));
- Struts2--简单的数据校验
action没有request, response等属性, 无法往前台传信息, 出来一个概念, valuestack: 存放action的属性, 还有各种error等... <s:propert ...
- zookeeper启动失败
集群中3个节点,第一个started,第二个说Starting zookeeper ... already running as process xxxx,第三个说Starting zookeeper ...