Thursday, March 16, 2017

Javascript designing patterns


module Test.Caller {
 
    var app = (() => {
        var apiCalles = {
            getItems: () => {
                return $.ajax({
                    url: 'http://localhost:58261/api/some/getValues',
                    contentType: 'application/json',
                });
            }
        }
        function listItems(e) {
            alert($(e.target).attr('id'));
            apiCalles.getItems().done((e) => {
                console.log();
            }).fail((e) => {
                console.error(e);
            });
        }
        function initControles() {
            $('#btn').off('click').on('click', listItems.bind(this));
        }
        var validation = {
            form1: () => { },
            form2: () => { }
        };
        return {
            init: () => { initControles(); }
        }
    })();
 
    $(document).ready(app.init);
}

//////////////////////////////////////////////////////////////////

var app2 = {
 
    bindEvents() {
        $('#btn').off('click').on('click', this.toggleTime.bind(this));
    },
    toggleTime(e) {
        alert($(e.target).attr('id'));
    }, init() {
        var $self = app2;
        $self.bindEvents();
    },
}
$(document).ready(app2.init);

No comments:

Post a Comment

CS Events