pubsubz/pubsubz.js
key point:
publish(topic, args): 執行特定topic的所有subscriber的func,並將參數args傳入
subscribe(topic, func): 將特定topic跟func綁定,以便publish中使用
unsubscribe: 移除 subscriber
Usage:
// 要綁定的 func var mlog = function (t, d) { console.log(t+ ": " + d);}; // 綁定 topic (inbox/newMessage) 跟 mlog var subscription = pubsub.subscribe("messagee", mlog); // publish ! pubsub.publish("message", "hello world!"); pubsub.publish("message", ["test", "a", "b", "c"]);
沒有留言:
張貼留言