title: javascript - Coffeescript & Backbone.js - TypeError: this._ensureElement is not a function
body: <p><strong>.: EDIT :.</strong>
  If you are having the same problem check your variable initialization, i forgot about <em>new</em>.</p>
  
  <p>I keep getting <em>TypeError: this._ensureElement is not a function</em> and got <em>TypeError: this._reset is not a function</em> once earlier but I can't really recreate the exact setup for the latter.</p>
  
  <p>I have my scripts in right order:</p>
  
  <pre><code>&lt;script src="js/components/jquery.js"&gt;&lt;/script&gt;
  &lt;script src="js/components/underscore.js"&gt;&lt;/script&gt;
  &lt;script src="js/components/backbone.js"&gt;&lt;/script&gt;
  &lt;script src="js/script.js"&gt;&lt;/script&gt;
  </code></pre>
  
  <p>My model is registered before my collection.</p>
  
  <p>It's a shopping cart app.</p>
  
  <pre><code>#namespacing
  
  App =
    Collection : {}
    Model : {}
    View : {}
  
  ###
  MODEL
  ###
  
  class ModelItem extends Backbone.Model
  
    #default values
  
    defaults:
      name : 'Product Name' 
      quantity : 0
      unit : 'kg'
  
    #Increase or decrease the quantity
  
    change_quantity : (type) -&gt;
      qty = @get 'quantity'
      @set 'quantity', if type is 'increase' then ++qty else --qty
  
  ###
  COLLECTION
  ###
  
  class CollectionItems extends Backbone.Collection
  
    model: ModelItem
  
  ###
  VIEW
  ###
  
  class ViewItems extends Backbone.View
  
  window.view = ViewItems()
  window.item = ModelItem()
  </code></pre>