4 ms·
This looks like a great tutorial, but please, for the love of maintainability stop stringing (pun intended) your views together by concatenating a bunch of line
by Pewpewarrows 16y ago
This looks like a great tutorial, but please, for the love of maintainability stop stringing (pun intended) your views together by concatenating a bunch of lines together all over the place.
Underscore.js (which is required (and from the same team) for using Backbone) has a built-in templating with logic feature. In your html make a <script type="text/html"></script> with your template code inside of it, which will be overlooked by the browser during rendering, but you can still select and get the contents of it by slapping on an id. Then it's just a quick call to _.template() with your data object and it renders out beautifully. It feels analogous to your usual MVC structure, and is much easier to debug and update.
- jashkenas 16y agoJames is also using Jammit here, which has built-in support for JavaScript templates (of any flavor). I agree that it would simplify the tutorial to get all of that string concatenation out of there. That said, he clearly thinks that leaving templates out of it is the simpler solution: "For the purposes of this tutorial, I'll use simple string concatenation in my views." And from the point of view of someone just getting started, he may very well be right.