Skip to content

Instantly share code, notes, and snippets.

@tbranyen
Created September 8, 2011 03:04
Show Gist options
  • Save tbranyen/1202511 to your computer and use it in GitHub Desktop.
Save tbranyen/1202511 to your computer and use it in GitHub Desktop.
basic module function
(function(self) {
self.Model = Backbone.Model.extend({
defaults: {
beverage: 'Orange Soda',
yogurt: false,
fruits: ['Apple', 'Plum', 'Watermelon']
}
});
})(module('breakfast'));
(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'));
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: {} };
};
}();
@cowboy
Copy link

cowboy commented Sep 9, 2011

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment