title: How can I enforce attribute types in a Backbone model?
body: <p>I want to have a Backbone model with float attributes in it but without worrying too much about variable types. </p>
  
  <p>I would like to encapsulate the value parsing right there in the model so I am thinking of overriding the <code>set</code> function:</p>
  
  <pre><code>var Place = Backbone.Model.extend({
    set: function(attributes, options) {
      if (!_.isEmpty(attributes.latitude)){
        attributes.latitude == parseFloat(attributes.latitude);
      }
      if (!_.isEmpty(attributes.longitude)){
        attributes.longitude == parseFloat(attributes.longitude);
      }
      Backbone.Model.prototype.set.call(this, attributes, options);
    }
  });
  </code></pre>
  
  <p>However this seems cumbersome, since I would have a similar logic in the validate method and potentially repeated across multiple models. I don't think the View should take care of these conversions. </p>
  
  <p>So what is the best way of doing it? </p>