A JavaScript constructor function that implements the publish / subscribe pattern. Supports in browser usage and as a node module.
#PS.js
##Browser Usage Minified and unminified versions in the dist folder.
<script src="pubsub.min.js"></script>
<script>
var ps = new PS();
</script>
##Node.js Usage
npm install dtang-pubsub
Link to NPM page: https://npmjs.org/package/dtang-pubsub
var Evt = require('pubsub');
var ps = new Evt.PS();
##Public Methods
####publish(topic, [data])
####subscribe(topic, callback, [context])
####unsubscribe(subscriptionID)
##Examples
var ps = new PS();
var s1 = ps.subscribe('test-topic', function(data) {
console.log(this, data);
});
// 3rd argument will be the context used for the 2nd argument
var s2 = ps.subscribe('test-topic', function(data) {
console.log(this, data);
}, {
name: 'David',
age: 27
});
ps.publish('test-topic', 'some data');
ps.unsubscribe(s1); // unsubscribes s1
console.log(ps);