Created
March 29, 2012 08:06
-
-
Save samuelcotterall/2234777 to your computer and use it in GitHub Desktop.
Module Pattern Redux
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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