3 ms·
I'd be interested to know how this compares to js-model (http://benpickles.github.com/js-model/ http://benpickles.github.com/js-model/). Anyone have any insight
by itrekkie 16y ago
I'd be interested to know how this compares to js-model (http://benpickles.github.com/js-model/ http://benpickles.github.com/js-model/). Anyone have any insight?
- jashkenas 16y agoYes. 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.
- swannodette 16y agoSimilar but it does seem to conflate the idea of a Model and a Collection. Also the instance changes API in js-model prefers an interface based around instance mutability instead of presenting the old and new value in a functional manner to the callback. BackBone.js Models are also mutable. This is probably the only part of the design I would have handled differently at the cost of responsiveness in browsers with slower JS engines. In my experience it's too easy to accidentally corrupt the data which populates many UI components if you're passing mutable references around.