Joe Honton
Mar 18, 2021

--

I am one of the zealots who use Object.seal(this) as the last line of almost every class constructor. It gives me the comfort that an inadvertent misspelling won't creep into my codebase and go unnoticed.

For me, a constructor is a contract with my future self: "this is the shape of this object, it has exactly these properties". If I don't intend to adhere to such a contract, I use an unsealed anonymous Object.

--

--

Joe Honton
Joe Honton

Written by Joe Honton

Princeps geographus, Read Write Tools

Responses (1)