Created
September 8, 2011 03:04
-
-
Save tbranyen/1202511 to your computer and use it in GitHub Desktop.
basic module function
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
(function(self) { | |
self.Model = Backbone.Model.extend({ | |
defaults: { | |
beverage: 'Orange Soda', | |
yogurt: false, | |
fruits: ['Apple', 'Plum', 'Watermelon'] | |
} | |
}); | |
})(module('breakfast')); |
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
(function(self) { | |
// Import the breakfast module | |
var Breakfast = module('breakfast'); | |
self.Views.ShowBreakfast = Backbone.View.extend({ | |
initialize: function() { | |
this.breakfast = new Breakfast.Model(); | |
}, | |
render: function() { | |
console.log(this.breakfast.toJSON()); | |
} | |
}); | |
})(module('meals')); |
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
module = function() { | |
// Internal module cache. | |
var _modules = {}; | |
// Create a new module reference scaffold or load an | |
// existing module. | |
return function(name) { | |
// If this module has already been created, return it. | |
if (_modules[name]) { | |
return _modules[name]; | |
} | |
// Create any custom properties you want all modules to have access to. | |
// Return the module. | |
return _modules[name] = { Views: {} }; | |
}; | |
}(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Check this out: https://gist.github.com/1206902