cliffeh (2) [Avatar] Offline
#1
Hello! Thanks for your work on this book, I'm through Chapt 2 & like it so far.

One question, though. In Figure 2.4, you say "Models have their own View", and in the renderComment() method of the CommentsView, you do set a view property on your model.

Maybe it's a matter of opinion, but I prefer models to not know anything about views. In your renderComment() method, you wouldn't need to assign a view property to the model, just do var view =..., and then call view.render(), keeping the model out of it.

In our application, we've reused models across views (e.g. a ReadonlyCommentView and an EditCommentView), but that only works because our models are view-agnostic.

Thoughts? Thanks again for what's shaping up to be a good book
Cliffe
rasorface (2) [Avatar] Offline
#2
Re: Models have their own View?
Models having knowledge of views would not be the way I'd go. Here is a post (https://devblog.supportbee.com/2011/07/29/backbone-js-tips-lessons-from-the-trenches/) that makes a pretty good argument why you might not want to do that. It discusses the classic ToDo example, which did have models saving references to views. There are some other interesting ideas presented, too.