Overview and bullshit-dispelling

You have models and collections (the data layer), views (or controllers, name it as you will), and URLs. As is with nearly every other popular framework or library of this kind.

★ ★ ★

The rule of thumb is get the hell away from the DOM. You won’t read from it ever (e.g.: getting an element’s class name, or the length of a list counts as that), because your data layer knows what has what value and in what state anything is at at any given time. You’ll write to the DOM only by rendering views. If you like this approach, it’s totally ok to use just regular JS or jQuery.

★ ★ ★

Small modules built outside of Backbone (read: are not a model/view/router) are ok. So long as they perform one function and are clear in what they in turn require, it’s all good.

★ ★ ★

Common architecture mistakes involve getting one or more of the previous statements wrong, bending the rules “a little”, or however else you excuse it.

★ ★ ★

This is what every JavaScript framework powered app does most of the time: they get views to track changes in data, and re-render the associated view(s) in more or less granular fashion.

★ ★ ★

It’s entirely possible to make stupid mistakes with any framework. To say one is less prone to idiocy than the other is an attempt at misguiding you. Every popular framework provides tools for data handling, presentation, and URLs. It’s up to you to know how to use that effectively.

★ ★ ★

The goal is creating a fast, beautiful, and maintainable build, and that’s achieved by doing things right through the entire stack (so HTML and CSS too), as well as a great design, and not just the application logic. No tool will save you from that fact. Citing an app as evidence of a framework “being better” conveniently leaves this out, which means it’s a cheap attempt at selling it to you.

★ ★ ★

Pick a tool and go with it. Stop asking questions such as “Is Angular better than Backbone?”. It’s a huge waste of time even thinking about it until you’re well into a handful of apps and made a lot of mistakes which you learned from.

★ ★ ★

You can create patterns on top of Backbone once you mastered it. A lot of projects out there consist of that, like Chaplin. Though most of the time you’ll get away without needing any of that.

★ ★ ★

Sadly, you don’t need a license stating that you’re capable of using functions and modules correctly before you’re legally allowed to use OOP. Throughout this booklet I’ll refer to modules many times because it’s the best way to structure your code. There's no shortage of module systems for browsers, but to cut a long story short, read about browserify and learn it.

Understand though that for a piece of code to be modular, it doesn't require the blessing of one of those libraries. Read: if you're smart about it, you get to export modules/classes/libraries to the global scope without any real damage to how an app is structured.

★ ★ ★

Think twice before adding a plugin. It doesn’t matter how awesome your favourite website says it is. $10 says they never used it themselves. Hell is other people’s code, and the way to it is paved by assumptions that shit just works. Really try to solve the problem first. You’ll get good at that, and then nothing will stop you.

C J