Backbone Directives

2014-08-11 00:00:00 +0100 by Alex R. Young

Tal Bereznitskey writes:

This is an open source project to enrich Backbone.js with AngularJS style directives.

I used to hear people talk about the new hotness and I didn't really want to let go of Backbone. I took quick looks from time to time and found some stuff I didn't like in AngularJS.

The DOM was filled with things like "ng-click" which reminded me of the spaghetti age of HTML and JavaScript.

When I first started using Angular I also found custom attributes (directives) concerning. However, after using them I realised that they can really help make code more declarative and concise. Tal came to the same conclusion, and created Backbone Directives (GitHub: berzniz / backbone.directives, License: MIT) to bring the same pattern to Backbone projects.

It includes things like bb-bind which implements data-binding with expression support, and bb-class for changing an element's class.

Expressions use the same code as Angular's expression parser, which attempts to safely execute JavaScript by using a sandbox that prevents access to certain properties (like .constructor).

```javascript // Sandboxing Angular Expressions //