0

I want to call onCallback inside the closure function, Is there a better way? Thanks for your comments and advice.

$.A.commentForm = function() {
    var hasWritten = false;
    var that = this;

    return {
        init: function () {
            $('#commentWriteForm').submit(this.onSubmit);
        },

        onSubmit: function (e) {
            var $form = $('#commentWriteForm');
            e.preventDefault()
            $.post($form.attr('action'), $form.serialize(), $.A.commentForm.onCallback, 'json');
            //                                               ^^^^^ how to refactor this?
        },

        onCallback: function (data) {
            /* ... */
        }
    };
}();

$.A.commentForm.init();
user1035957
  • 327
  • 1
  • 3
  • 9

0 Answers0