title: Backbone.js: View with Reference to Model and Collection ... smell?
body: <p>I have a view for individual Customer models that takes a customer and collection of customers on construction.  The requirement of the customer model makes sense -- it is a view for a customer.  The requirement of the collection ... I'm not sure if that is a smell or not and would love feedback!</p>
  
  <p>The reason it needs the collection is so that a button in the view can remove the customer from the customers collection and that the view can also listen to collection remove events to see if it has to be unrendered (it was successfully removed from the collection).</p>
  
  <pre><code>    var CustomerView = Backbone.View.extend({
  
          events: {
              'click button.delete': 'remove'
          },
  
          initialize: function() {
              _.bindAll(this, 'render', 'unrender', 'remove', 'removed');
  
              this.model.bind('change', this.render);
              this.collection.bind('remove', this.removed);
          }
  
          // render / unrender removed for brevity
  
          remove: function () {
              this.collection.remove(this.model);
          },
  
          removed: function (customer) {
              if (this.model === customer) {
                  this.unrender();
              }
          }
      });
  </code></pre>
  
  <p>Here is how the view is created:</p>
  
  <pre><code>    var CustomersView = Backbone.View.extend({
  
          initialize: function () {
              _.bindAll(this, 'appendCustomer');
  
              this.model.customers.bind('add', this.appendCustomer);
          },
  
          appendCustomer: function (customer) {
              var customerView = new CustomerView({
                  model: customer,
                  collection: this.model.customers
              });
  
              $(this.el).append(customerView.render().el);
          }
       });
  </code></pre>
  
  <p>I was thinking I could somehow wire up the CustomerView in this appendCustomer method instead of simply giving the customers collection to the CustomerView wholesale.</p>
  
  <p>Thoughts?  Thanks!</p>