Object literals and event listeners

December 5, 2013

 var testObj = {
    handlers: {
        '#form submit': 'onSubmit'
    },
    registerHandlers: function() {
        var that = this;
        $.each(this.handlers, function(k, v) {
            var split = k.split(" "),
                el = split[0],
                trigger = split[1];
            $(document).delegate(el, trigger, that[v]);
        });
    },
    onSubmit: function(evt) {
        evt.preventDefault();
        alert("submit");
    }
};

Comments

comments powered by Disqus