Skip to content

Instantly share code, notes, and snippets.

@satendra02
Last active February 19, 2018 18:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save satendra02/24d37299ac54beb9336dd4440589ebea to your computer and use it in GitHub Desktop.
Save satendra02/24d37299ac54beb9336dd4440589ebea to your computer and use it in GitHub Desktop.
Override fabric Object to add custom attribute
//when you export canvas.toJSON(), the object will cointain `your_custom_attribute`
//{“objects”: [{“src”: “”, “your_custom_attribute”: “”, “type”: “image”, …}, {}], “version”: “2.0.0-rc.4” }
fabric.Object.prototype.toObject = (function (toObject) {
return function (propertiesToInclude) {
propertiesToInclude = (propertiesToInclude || []).concat(
['your_custom_attribute', ...]
);
return toObject.apply(this, [propertiesToInclude]);
};
})(fabric.Object.prototype.toObject);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment