title: Trouble overriding toString on object/class
body: <p>As the title says, I'm trying to implement some conditional display logic to my form built using <a href="https://github.com/powmedia/backbone-forms" rel="nofollow noreferrer">backbone-forms</a>. The environment also uses Backbone.js, Underscore.js and jQuery.</p>
  
  <p>I have reviewed the similar question here on SO "<a href="https://stackoverflow.com/questions/11433314/backbone-forms-with-conditional-fields">backbone-forms with conditional fields</a>", but our use case is a bit different: we have fields that depend on multiple conditions (e.g. only display if foo=1 and bar=2).</p>
  
  <p>[<em>edit: I've already written a generic form change event handler to handle hiding and showing the different fields, so I don't want suggestions about that part.</em>]</p>
  
  <p>I'm trying to use data attributes to contain a JSON representation of the field's conditions, but I'm open to other solutions. Here's roughly what I'm currently trying to achieve:</p>
  
  <p><code>&lt;input id="field3" name="field3" data-conditional-conditions='{"field1":"yes","field2":"yes"}' type="text"&gt;</code></p>
  
  <p>I've discovered that backbone-forms uses jQuery's <code>attr()</code> method to set any properties specified in the model's <code>schema</code> (<a href="https://github.com/powmedia/backbone-forms/blob/master/src/editor.js#L47" rel="nofollow noreferrer">here's the relevant line in backbone-forms' source</a>), and it seems that <code>attr()</code> in turn uses <code>Object.prototype.toString()</code> to represent an object as a value when rendering the editor.*</p>
  
  <p>So what I've been trying to do is implement a <code>Conditions</code> object as follows:</p>
  
  <pre><code>var Conditions = function(args){
  
      c = {
          toString: function(){
              return(JSON.stringify( _.omit(this, _.functions(this)) ));
          }
      };
  
      c.toString = _.bind(c.toString, c); //makes 'this' refer to the 'c' object
  
      args = _.isObject(args) ? args : {}; //default value for args
  
      c = _.defaults(c, args); //sets object key/value pairs from arguments
  
      return c;
  };
  </code></pre>
  
  <p>My goal with the above was to replace the <code>toString()</code> method with one that would return a JSON-formatted representation of the object, without having to modify backbone-forms.</p>
  
  <p>Unfortunately, the above doesn't quite work, as the form field appears as follows:</p>
  
  <p><code>&lt;input id="field3" name="field3" tostring="{"data-conditional-conditions":{"field1":"yes","field2":"yes"}}" data-conditional-conditions="[object Object]" type="text"&gt;</code></p>
  
  <p>I'm reaching the end of my JavaScript knowledge, and frustrated by what's going on. I've tried using IIFEs and returning c.toString from my Conditions function, but neither of those have worked.</p>
  
  <p>Thanks for reading, and I look forward to your suggestions!</p>
  
  <p><em>*: I've inferred this because if I call <code>attr({"data-key": {"foo": "bar"} })</code>, the result looks like <code>&lt;div data-key="[object Object]"&gt;</code></em></p>