title: Nested Models in Backbone.js, how to approach
body: <p>I've got the following JSON provided from a server. With this, I want to create a model with a nested model. I am unsure of which is the way to achieve this. </p>
  
  <pre><code>//json
  [{
      name : "example",
      layout : {
          x : 100,
          y : 100,
      }
  }]
  </code></pre>
  
  <p>I want these to be converted to two nested backbone models with the following structure:</p>
  
  <pre><code>// structure
  Image
      Layout
  ...
  </code></pre>
  
  <p>So I define the Layout model like so:</p>
  
  <pre><code>var Layout = Backbone.Model.extend({});
  </code></pre>
  
  <p>But which of the two (if any) techniques below should I use to define the Image model? A or B below?</p>
  
  <p><strong>A</strong></p>
  
  <pre><code>var Image = Backbone.Model.extend({
      initialize: function() {
          this.set({ 'layout' : new Layout(this.get('layout')) })
      }
  });
  </code></pre>
  
  <p><em>or,</em> <strong>B</strong></p>
  
  <pre><code>var Image = Backbone.Model.extend({
      initialize: function() {
          this.layout = new Layout( this.get('layout') );
      }
  });
  </code></pre>