I have this custom stringify function which can handle circular references:
const customStringify = function (v) {
return JSON.stringify(v, function(k, v) {
if (v instanceof Node) {
return 'Node';
}
if (v instanceof Window) {
return 'Window';
}
return v;
});
};
but if I use it to stringify an event object:
window.addEventListener('click', function (ev) { // MouseEvent
const v = customStringify(ev); // {"isTrusted":true}
});
v is just string that looks like this:
{"isTrusted":true}
so bizarre. I tried a few other custom stringifying helper functions, and they all give me the same result.
I looked at this thread: How to stringify event object?
but my problem seems more specific.