title: Collection is not a function or Collection is not a constructor in Backbone
body: <p>This code of mine keeps on throwing error i don't understand why.</p>
  <pre><code>var id = $(ev.currentTarget).data(&quot;id&quot;);
      var item = ItemCollection.getByCid(id);
      alert(item.get(&quot;ItemCode&quot;));
      var qty = 1;
      var cartcollection = new CartCollection();
      cartcollection.add( item );
      CartListView.render();
      var itemcode = cartcollection.where({ItemCode: item.get(&quot;ItemCode&quot;)});
      if( itemcode.length &gt; 0 ){ alert(&quot;success&quot;); }
  </code></pre>
  <p>So what i want to do is check if the CartCollection has the same model already and if true it should update the Qty atrib of the model only. Now based on that code it returns CartCollection is not a function or not a constructor. Why the hell is that!? Any ideas? Thanks</p>
  <h1>Update</h1>
  <p>I'm using backbone,require,KendoUI grid and underscore on this one so my code is this:</p>
  <p>itemlist_view.js</p>
  <pre><code>define([
  'jquery',
  'underscore',
  'backbone',
  'model/item_model',
  'model/cart_model',
  'collection/item_collection',
  'collection/cart_collection',
  'view/cart/cartlist_view',
  'text!templates/items/itemlist.html'
   ],function($, _, Backbone, Item, Cart, ItemCollection, CartCollection, CartListView, ItemListTemplate){
  
  var ItemListView = Backbone.View.extend({
  el: $(&quot;#mainContainer&quot;),
  events:{
      &quot;click #itemListContainer li&quot; : &quot;AddToCart&quot;
  },
  initialize: function(){
    this.model = Item;
    this.collection = ItemCollection;
    this.collection.bind(&quot;reset&quot;, this.render );
  },
  render: function(){
    var data = {
      items: ItemCollection.models
    }
    var compiledTemplate = _.template( ItemListTemplate , data);
    $(&quot;#itemContainer&quot;).html( compiledTemplate );
  },
  AddToCart:function(ev){
      ev.preventDefault();
      var id = $(ev.currentTarget).data(&quot;id&quot;);
      var item = ItemCollection.getByCid(id);
      alert(item.get(&quot;ItemCode&quot;));
      var qty = 1;
      var cartcollection = new CartCollection();
      cartcollection.add( item );
      CartListView.render();
      var itemcode = cartcollection.where({ItemCode: item.get(&quot;ItemCode&quot;)});
      if( itemcode.length &gt; 0 ){ alert(&quot;success&quot;); }
  }
  });
  return new ItemListView;
  });
  </code></pre>
  <p>cart_collection.js</p>
  <pre><code>define([
  'underscore',
  'backbone',
  'model/cart_model'
  ],function(_, Backbone, Cart){
  var CartCollection = Backbone.Collection.extend({
      model: Cart,
    initialize: function(){
  
    }
  });
  return new CartCollection;
   });
  </code></pre>
  <p>cartlist_view.js</p>
  <pre><code>define([
   'jquery',
   'underscore',
   'backbone',
   'model/cart_model',
   'collection/cart_collection',
   'text!templates/cart/cartlist.html'
   ], function($, _, Backbone, Cart, CartCollection, CartListTemplate){
  
  var Model = kendo.data.Model,
      ObservableArray = kendo.data.ObservableArray;
  
  function wrapBackboneModel(backboneModel, fields) {
      return Model.define({
          fields: fields,
          init: function(model) {
              if (!(model instanceof backboneModel)) {
                  model = new backboneModel(model);
              }
  
              Model.fn.init.call(this, model.toJSON());
              this.backbone = model;
          },
          set: function(field, value) {
              Model.fn.set.call(this, field, value);
  
              this.backbone.set(field, value);
          }
      });
  }
  
  function wrapBackboneCollection(model) {
      return ObservableArray.extend( {
          init: function(collection) {
              ObservableArray.fn.init.call(this, collection.models, model);
  
              this.collection = collection;
          },
  
          splice: function(index, howMany) {
              var itemsToInsert, removedItemx, idx, length;
  
              itemsToInsert = Array.prototype.slice.call(arguments, 2);
  
              removedItems = kendo.data.ObservableArray.fn.splice.apply(this, arguments);
  
              if (removedItems.length) {
                  for (idx = 0, length = removedItems.length; idx &lt; length; idx++) {
                      this.collection.remove(removedItems[idx].backbone);
                  }
              }
  
              if (itemsToInsert.length) {
                  for (idx = 0, length = itemsToInsert.length; idx &lt; length; idx++) {
                      this.collection.unshift(itemsToInsert[idx].backbone);
                  }
              }
  
              return removedItems;
          }
      });
  }
  
  kendobackboneCollection = wrapBackboneCollection;
  kendobackboneModel = wrapBackboneModel;
  
  
  var CartListView = Backbone.View.extend({
  el: $(&quot;#cartContainer&quot;),
  
  initialize: function(){
    this.collection = CartCollection;
    this.model = Cart;
    this.collection.bind(&quot;change&quot;, this.render );
  },
  render: function(){
    console.log(&quot;here&quot;);
    this.el.html(CartListTemplate);
    var CartWrapper = kendobackboneModel(Cart, {
       ItemCode: { type: &quot;string&quot; },
       ItemDescription: { type: &quot;string&quot; },
       RetailPrice: { type: &quot;string&quot; },
       Qty: { type: &quot;string&quot; },
    });
    var CartCollectionWrapper = kendobackboneCollection(CartWrapper);
  
    this.$(&quot;#grid&quot;).kendoGrid({
      editable: true,
      toolbar: [&quot;create&quot;],
      columns: [&quot;ItemDescription&quot;, &quot;Qty&quot;, &quot;RetailPrice&quot;],
      dataSource: {
        schema: {model: CartWrapper},
        data: new CartCollectionWrapper(CartCollection),
       }
    });
    
  },
  
  });
  return new CartListView;
  });
  </code></pre>