Internally, the special handlers for Date, Map, and Set are moved to use this mechanism to keep code tidy.
Limitations
Note that - for performance - this is backed under the hood by a Map with the classes as keys, which gives constant-time lookup (compared to eg iterating over an array of handlers). A limitation that this introduces is that subclasses would not be matched, and would need their own handlers, since we don't look up the prototype chain.
The motivation of this change is to allow passing custom handlers for particular classes. For example,
ObjectId
.These can be passed using the new
constructorHandlers
option:Similarly,
RegExp
support can be added manually:Internally, the special handlers for
Date
,Map
, andSet
are moved to use this mechanism to keep code tidy.Limitations
Note that - for performance - this is backed under the hood by a
Map
with the classes as keys, which gives constant-time lookup (compared to eg iterating over an array of handlers). A limitation that this introduces is that subclasses would not be matched, and would need their own handlers, since we don't look up the prototype chain.Performance
Benchmarks before:
Benchmarks after: