FabricJs - How do I Add properties to each object

fabricjs

Solution

As of version 1.7.0 levon's code stopped working. All you need to do is to fix as follows:

// Save additional attributes in Serialization
fabric.Object.prototype.toObject = (function (toObject) {
    return function (properties) {
        return fabric.util.object.extend(toObject.call(this, properties), {
            textID: this.textID
        });
    };
})(fabric.Object.prototype.toObject);

You have to receive `properties` argument and pass it on to `toObject`.

Problem

I need to introduce few additional properties to existing object properties set. like: - ID - Geo Location - etc Whenever I draw a shape, I need to add additional properties to the shape and need to get from `toDataLessJSON()`

Original source