Demo http://jsfiddle.net/uAQn9/
Code:
function Event() {
}
Event.prototype = {
trigger:function(eventName, arParam) {
$(window).trigger(eventName, arParam);
},
on: function(eventName, cb) {
var event = this;
$(window).on(eventName, function(e) {
var args = Array.prototype.slice.call(arguments);
cb.apply(event, args.slice(1));
});
return this;
}
}
//CODE1:
var e = new Event();
e.on('myevent', function (a, b) {
console.log(a + ' ' + b);
});
e.trigger('myevent', ['Hello', 'world']);
//CODE2:
e.on('hello', function() {
console.log('Hello');
this.trigger('world');
}).on('world', function() {
console.log('World');
}).trigger('hello');