Posts

Showing posts from May, 2013

Understanding backbone.js extend method, a meta factory

Reading Backbones code makes me think of a Japanese zen garden or old style Japanese dwelling. There is no waste or excess. It's like an author who rewrote and improved their work over and over such that each statement belongs. Not an instruction is wasted. Its minimal but very powerful. The following is my step by step timeline analysis of the Backbone library for how custom Classes are created from the core Backbone classes such as Model, View and Collection. I will focus on Backbone.Model but the same creation pattern is used for Backbone Model, Collection and View ....but not Backbone.Events. Backbone.Events is just a plain object literal with properties. Step 1. Backbone.Model is declared as a function:  var Model = Backbone.Model = function(attributes, options) { .. } Backbone.Model is a function. Functions are objects in js. Every object in js has a prototype property which points to an object. Functions inherit from Function.prototype (which has methods like