2 ms·
Yes. I recently discovered js-model while wrapping up the Backbone documentation. The two libraries are extremely similar, and share the same core idea, but wit
by jashkenas 16y ago
Yes. I recently discovered js-model while wrapping up the Backbone documentation. The two libraries are extremely similar, and share the same core idea, but with that said, here are some of the differences:
* js-model is explicitly inspired by Rails' ActiveRecord models, and a lot of these points fall out from that fact...
* In js-model, a collection and a model class (constructor function) are the same object. This is a big problem in client-side code -- you don't always want to have just a single collection of say, notes. That makes sense in a one-database-per-app, one-table-per-model world, but not so much in JavaScript.
* Backbone sets up the prototype chain so that you can continue to extend (subclass) your Models, Collections, and Views.
* Backbone includes a richer set of enumerable functions, based on Underscore.js, so you get native performance in browsers that support them natively.
* js-model's validation and errors API mimics Rails' Errors object, which may or may not be what you want.
* Backbone includes Views, and js-model sticks to models.
That's just a list of things off the top of my head. It's an amazing example of convergent evolution in code -- and I think it's much more widespread than this. In my experience, many folks who work on big JavaScript projects end up with an internal framework that bears an uncanny resemblance to Backbone.
- netghost 16y agojs-model has some nice support for serializing to local storage and so forth baked in, which I've found to be really handy. Backbone looks like it forms a much more cohesive package though, which is nice.