Languages / JavaScript Core
Objects and Classes
Properties, prototypes, classes, and metaprogramming with Proxy.
Photo by chansu shin on Unsplash
Objects in JavaScript
Plain objects are string-keyed maps with a prototype chain, not fixed structs like C structs or Java POJOs. Literals, property access, shorthand, computed keys, and references versus copies set the baseline for everything else in this series.
Defining object properties in JavaScript
Object.defineProperty and friends attach data or accessor descriptors with explicit writable, enumerable, and configurable flags—closer to Java Bean descriptors than to a simple field assignment.
Filter object properties by key
Pick or drop keys on a plain object without mutating the original—destructuring for one key, Object.fromEntries with filter for allowlists.
Prototypes and inheritance
JavaScript links objects through prototypes, not class tables copied at compile time. Property lookup walks the chain; methods live on shared prototype objects—similar in spirit to Ruby modules, unlike Java subclass field layout.
Classes in JavaScript
class syntax is mostly syntactic sugar over prototypes: constructors install own state, methods live on the prototype, extends wires the chain. Fields, private #members, and static blocks match what Java or C# developers expect with a few JavaScript-specific rules.
Freezing and sealing objects
Object.preventExtensions, seal, and freeze tighten what can change on an object—useful for config snapshots and defensive copies, not deep immutability.
Proxy and Reflect
Proxy wraps an object and intercepts get, set, and other operations— validation, logging, reactivity, and virtual properties. Reflect mirrors those operations as functions for consistent defaults in traps.