Last active
February 19, 2018 18:04
-
-
Save satendra02/24d37299ac54beb9336dd4440589ebea to your computer and use it in GitHub Desktop.
Override fabric Object to add custom attribute
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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