Skip to content

Instantly share code, notes, and snippets.

@samuelcotterall
Created March 29, 2012 08:06
Show Gist options
  • Save samuelcotterall/2234777 to your computer and use it in GitHub Desktop.
Save samuelcotterall/2234777 to your computer and use it in GitHub Desktop.
Module Pattern Redux
function newMyApp() {
var x = 1;
var y = 2;
var that = {};
function fullName(fn,sn){
return fn + sn;
}
return {
// Configuration options
conf : {
'firstname' : 'John', // myApp.conf.firstname
'surname' : 'Doe' // myApp.conf.surname
},
// Setup methods
setup : {
// myApp.setup.setupMethod1();
setupMethod1 : function(){
var t = this;
$(t.objHeader).text(t.fullName);
},
// myApp.setup.setupMethod2();
setupMethod2: function(){
// ...
}
},
init : function(){
var t = this;
// Vars
t.fullName = fullName(myApp.conf.firstname, myApp.conf.surname);
// Object Reference
t.objHeader = $("#header");
// Proceed
t.setup.setupMethod1();
}
};
}
var myApp = newMyApp();
$(document).ready(function(){
myApp.init();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment