When building your application you may need to attach to objects some custom properties.
One very common need is to have an id or a name on objects.
If you are using Typescript or if you want your IDE to suggest you completition you will need to clearly state which those properties are.
On top of that there is the serialization issue that will require you to pass down those properties in the argument of the function toObject.
To make this nicer you have to use the Typescript feature for interfaces and a custom property hook in the object class
This change will make the types work correcty:
Custom methods
In general it makes things simplier if you can stick to external utility functions, but in the cases in which you want to attach a specific method to the prototype of different classes, you have to do modify the interface again:
Subclassing
Subclassing is easier but is not always possible.
If you want to subclass leaf nodes like Rect, Textbox, IText, Path, that is possible and easy
But you can’t subclass FabricObject and add it back in the prototype chain of the other objects.
Warning
You should add custom properties when they make your life simpler during rendering or event handling.
In general FabricJS classes/objects on the canvas shouldn’t contain data that is not relevant to their rendering needs or behaviour configuration, they shouldn’t become data stores of your application.