I've been looking at frameworks to help me write better structured JS code and came across Backbone. It seems to have lots of functionality for creating classes with public and private properties and members, inheritance, etc.
Angular JS seems to do a load of completely different stuff like automatic binding of markup to model and lots of clever trickery for templating, filtering, sorting etc.
My question is not which should I choose, but is it sensible to use both? AngularJS looks really cool, but unless I'm missing something then it doesn't seem to provide any OO stuff for you to work with. Does this make sense?
I'm not sure that pairing Angular with another framework would really make a lot of sense, it's quite complete as it is.
Backbone on the other hand is more composable, for instance you might take a look at the Knockback project, which make Backbone and KnockoutJS work together quite nicely. Knockout takes a MVVM approach which is relatively close to what you'll find in Angular.
If you need to write OO for your data (aka Models), just use a library like Base.js. It gives you nice OO syntax, inheritance, with methods like extend
. The good part is that it keeps the getter syntax like myObject.var
so it plays nicely with Angular, contrarily to Backbone where you need to use a getter myObject.get('var')
, so data bindings works just fine.
To understand the difference and the reason between those syntaxes and philosophy, read one of the Angular author's answer here in SO.
AngularJS purposely does not impose any particular inheritance style, so you're free to do whatever you want. If you like Backbone.js's inheritance model, you can use underscore (which is included in Backbone.js) to provide the .extend
helper.