Last active
August 29, 2015 14:13
-
-
Save aegyed91/2af55054499fd56723ab to your computer and use it in GitHub Desktop.
JS learning
This file contains hidden or 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
| // 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