What I Learned When Overriding a Frozen Object

Nicholas Jamieson
5 min readDec 8, 2020
Photo by Annie Spratt on Unsplash

When solving a problem that involved a frozen object, I learnt a bit more about the details of JavaScript object property access and some of those details are kinda interesting.

The Problem

Recently, I replaced an ESLint rule that was specific to arrays — no-array-foreach — with a more general rule — no-foreach — that also effected failures for the Set, Map and NodeList types.

The no-foreach rule supports a types option — so the that the types for which it is enforced can be configured by the developer — and I planned to leverage that by deprecating and re-implementing no-array-foreach to use no-foreach internally.

Something like this:

alt (github.com)

Here, context’s options property is overwritten before it’s passed to the base rule’s create function. However, that fails with an error:

alt (github.com)

The property is read-only because ESLint calls Object.freeze on context before passing it the the rule’s create function.

--

--

Nicholas Jamieson

RxJS core team member; front-end developer; mentor; speaker; open-source contributor