Ability to add custom error messages for Object.freeze() & Object.seal() TypeErrors

Had a thought while reviewing Object.freeze() and Object.seal() documentation. I kind of wish those methods took a second argument, maybe a string error message or something like that, to help provide more context to whoever tries to mutate or reconfigure said object and receives the error.

It's great to know that something is frozen but also seems like an opportunity for a library author to point a developer in the right direction if they are trying to change something that they shouldn't, such as 'Utilize this API if you're looking to edit application state'.

Not sure. First post on this forum. Wonder what others think.

Cheers,
Brant

1 Like

It seems like you could achieve this with a Proxy already; it'd probably be worth doing that and seeing if the approach gains traction in the community.

2 Likes