Skip to content

Instantly share code, notes, and snippets.

@stacylondon
Last active August 29, 2015 14:20
Show Gist options
  • Save stacylondon/d37c61617bcf57f3ce6e to your computer and use it in GitHub Desktop.
Save stacylondon/d37c61617bcf57f3ce6e to your computer and use it in GitHub Desktop.
Refactor 2 - Add Namespace, Object Literal Notation
// -------------------------------------
// 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