Skip to content

Instantly share code, notes, and snippets.

@aegyed91
Last active August 29, 2015 14:13
Show Gist options
  • Save aegyed91/2af55054499fd56723ab to your computer and use it in GitHub Desktop.
Save aegyed91/2af55054499fd56723ab to your computer and use it in GitHub Desktop.
JS learning
// a constructor function
var Backbone = {
Module: {
extend: function(attributes) {
this.defaults = {
type: 'Ape',
name: 'Ati'
};
this.attributes = $.extend({}, this.defaults, attributes);
}
}
};
Backbone.Module.extend.prototype = {
toJSON: function() {
return this.attributes
}
};
// memoization
var App = {
module: function() {
var modules = {};
return function(name) {
if (modules[name]) {
return modules[name];
};
return modules[name] = {
views: {}
};
}
}()
};
// animal module
(function(AnimalModule) {
var m = AnimalModule;
m.AnimalModel = new Backbone.Module.extend({ name: 'Albert' })
})(App.module('animalmodule'));
// var a = App.module('animalmodule')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment