Hacker News new | ask | show | jobs
by vinkelhake 311 days ago
A simple example is `toJSON`. If an object defines that method, it'll get invoked automatically by JSON.stringify and it could have arbitrary side effects.

I think it's less about side effects being common when serializing, just that their fast path avoids anything that could have side effects (like toJSON).

The article touches briefly on this.

1 comments

Right, I get that you could define something to have side effects. My question is why would you? What are some expected visible side effects of converting something to json?

That said, I see that they called it out as you say, now. When I first read it, I thought they watched for side effects.

I'm assuming they have an allow list on all standard types. The date types, in particular, often have a toJson that seems like it should still be used? (Or am I wrong on that, too? :D )