Last active
August 29, 2015 14:20
-
-
Save stacylondon/d37c61617bcf57f3ce6e to your computer and use it in GitHub Desktop.
Refactor 2 - Add Namespace, Object Literal Notation
This file contains 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
// ------------------------------------- | |
// my-app.js | |
// ------------------------------------- | |
; | |
var myApp = myApp || {}; | |
(function($, myApp) { | |
'use strict'; | |
$.extend(myApp, { | |
init: function() { | |
this.commonStuff(); | |
}, | |
commonStuff: function() { | |
// common code across many or all pages | |
} | |
}); | |
})(window.jQuery, window.myApp); | |
$(document).ready(function() { | |
myApp.init(); | |
}); | |
// ------------------------------------- | |
// page-one.js | |
// ------------------------------------- | |
; | |
var myApp = myApp || {}; | |
myApp.pageOne = myApp.pageOne || {}; | |
(function($, myApp) { | |
'use strict'; | |
$.extend(myApp.pageOne, { | |
init: function() { | |
this.pageSpecificStuff(); | |
}, | |
pageSpecificStuff: function() { | |
// code specific to this page | |
} | |
}); | |
})(window.jQuery, window.myApp); | |
$(document).ready(function() { | |
myApp.pageOne.init(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment