title: fabricjs: export with custom canvas attributes
body: <p>With <code>canvas.toJSON();</code> I cannot export the custom canvas attributes.</p>
  
  <p>I have to use prototype of canvas. But I don't know how to build a prototype structure.</p>
  
  <p>Existing (allowed) data:</p>
  
  <pre><code>var clipFath = this.clipPath, data = {
           version: fabric.version,
           objects: this._toObjects (methodName, propertiesToInclude),
  };
  </code></pre>
  
  <p>I need it this way:</p>
  
  <pre><code>var clipFath = this.clipPath, data = {
           version: fabric.version,
           objects: this._toObjects (methodName, propertiesToInclude),
           custom_settings_json: this.custom_settings /* &lt;-- */
  };
  </code></pre>
  
  <p>Original source <a href="http://fabricjs.com/docs/fabric.js.html#line7698" rel="nofollow noreferrer">line 7698</a>: </p>
  
  <p>In the following example, I can add custom settings to fabric objects. I need a similar structure for canvas. <a href="https://stackoverflow.com/a/41425316/6320082">Source</a></p>
  
  <pre><code>fabric.Object.prototype.toObject = (function (toObject) {
    return function (propertiesToInclude) {
        propertiesToInclude = (propertiesToInclude || []).concat(
          ['custom_attr_1','custom_attr_2'] /* &lt;- */
        );
        return toObject.apply(this, [propertiesToInclude]);
    };
  })(fabric.Object.prototype.toObject);
  </code></pre>
  
  <p>I tried this to set for canvas, as below </p>
  
  <pre><code>var canvas = new fabric.Canvas('canvas');
  var custom = {
      "data1": 1,
      "data2": 2
  }
  canvas.custom_settings_json = custom;
  var json_data = canvas.toJSON();
  console.log(json_data);
  
  // console log:
  {
    "version":"2.4.1",
    "objects":[{.....}],
    "custom_settings_json": {
          "data1": 1,
          "data2": 2
    }
  }
  </code></pre>
  
  <p>But I am getting this result without <code>custom_settings_json</code> in <code>toJSON</code> output.</p>
  
  <pre><code>// console log:
  {
    "version":"2.4.1",
    "objects":[{.....}]
  }
  </code></pre>