Apr 4, 2013

Current most used JS pattern


var myObject = (function () {
    // private variables
    var ajaxUrl = '/path/to/ajax.html',
        selectorObj,
    // public variables
        obj = {};
    obj.publicVar = '';
    // private methods
    setupEventHandlers = function () {
    };
    // public methods
    obj.init = function () {
        setupEventHandlers();
    };
    return obj;
}());

$(function () {
    myObject.init();
});

No comments: