UNPKG

dtang-pubsub

Version:

A small PubSub library under the PS constructor function.

24 lines (17 loc) 462 B
<script src="src/PS.js"></script> <script> var ps = new PS(); var s1 = ps.subscribe('test-topic', function(data) { console.log("context", this, data); }); // 2nd param is the context of the cb function var s2 = ps.subscribe('test-topic', function(data) { console.log("context", this, data); }, { name: 'David', age: 26 }); ps.publish('test-topic', 'some data'); ps.unsubscribe(s1); // removes s1 from topicList console.log(ps); </script>