The toString() method looks up the type in the RGBAColor.serializationTypes Map; if it finds a function, it calls that with the RGBAColor as the sole argument and returns whatever the function returns. It's preloaded with UA-defined functions for “hex3”, “hex6”, “rgb”, “rgba”, “hsl”, and “hsla”.

Authors can define their own color formats by adding a fromFoo() to RGBAColor, a toFoo() to RGBAColor.prototype, and adding an appropriate serialization tag to RGBAColor.serializationTypes.