I am working on javascript project. In this I have to use JavaScript and jQuery no JavaScript / jQuery Libraries such as Backbone. Therefore, I am following prototype javascript. In this I have to listen to user events and take actions accordingly. I am currently handling these events like following
var Module = function (el) {
var self = this;
// I am handling click events in constructor here
$('.' + el).on('click', function (e) { e.preventDefault(); self.foo() })
};
Module.prototype = function () {
var foo = function () {
console.log();
};
return {
foo: foo
}
}();
It works fine. Second way is to listen these events inside $(function () { });
. However, this way it becomes messy at some point. My question is how can I make my own events object so that it listen these events and call appropriate function or module?