string ‘.selector’ instead of direct reference $(‘.selector’) var MyView = Backbone.View.extend({ }); ! new MyView({ el: ‘#putHere’ }); var MyView = Backbone.View.extend({ }); ! new MyView({ el: $(‘#putHere’) });
string ‘el’ // Ensure that the View has a DOM element to render into. // If `this.el` is a string, pass it through `$()`, take the first // matching element, and re-assign it to `el`. Otherwise, create // an element from the `id`, `className` and `tagName` proeprties. _ensureElement : function() { if (!this.el) { var attrs = this.attributes || {}; if (this.id) attrs.id = this.id; if (this.className) attrs['class'] = this.className; this.el = this.make(this.tagName, attrs); } else if (_.isString(this.el)) { this.el = $(this.el).get(0); } } (Backbone source)
- At the path of the eventual backend service var RipOff = Backbone.Model.extend({ url: ‘/that/place/’ }); ! var theDojoExperience = new RipOff(); theDojoExperience.fetch();
initialize: function () { this.answerSheet = this.options.answerSheet; } answerQuestion: function () { var answer = determineAnswer(); this.answerSheet.recordAnswer(answer); } }); ! var AnswerSheet = Backbone.Model.extend({}); ! var myAnswers = new AnswerSheet(); var newQuestion = new Question({ answerSheet: myAnswers });
etc. http://webtreatsetc.deviantart.com/art/9-Blue-Striped-Patterns-131303428 Free for personal/commercial ! Jeremy Ashkenas https://github.com/documentcloud/backbone/blob/master/LICENSE MIT license ! Dave Geddes, Jason LuBean, and Matt Werny For their topic suggestions