Deep copying in JavaScript
Deep copying in JavaScript is a mess if you do not know the tradeoffs. This post covers shallow vs deep copies, where JSON stringify and spread/Object.assign break down, and when structuredClone is the right tool.
Tagged Articles
18 articles
Deep copying in JavaScript is a mess if you do not know the tradeoffs. This post covers shallow vs deep copies, where JSON stringify and spread/Object.assign break down, and when structuredClone is the right tool.
A simple Express pattern for reading the host header, pulling out the subdomain, and normalizing hyphens so you can drive behavior off `whatever.yourdomain.com with` a wildcard DNS entry.
This is my movement cheat sheet for 2D games, with runnable examples. It covers distance checks, angle math, pursuit, projecting points (like gun barrels), rotation while moving, and Asteroids-style heading movement with friction.
A practical walkthrough of midpoint displacement (Diamond Square) for 2D canvas terrain. It explains the iterations, how roughness changes the look, and includes a JS implementation with notes on wrapping and scrolling.
A simple burn-away effect using pixel "fuel". I build a 2D grid of burn values, decrement neighbors as pixels burn out, and use step-based flags to keep the spread controlled, with an optional flame coloring pass..
Recreating a shaded-sphere effect using nothing but points on canvas. I break down the math (row width via Pythagoras), how the random threshold creates shading, and how a single divisor changes the look.
Part two of my canvas platformer series. I add world geometry, detect and resolve collisions by direction, and introduce grounded and jumping state so movement feels right.
Part one of my canvas platformer series. I set up a player, build a requestAnimationFrame loop, track keyboard input, add friction and gravity, and implement a basic jump.
I recreated the metaballs effect in JavaScript canvas using radial gradients and an alpha threshold. This post walks through the approach, includes the gists, and links a demo and JSFiddle to play with.
I implemented a recursive flood fill for a Rampart-ish canvas prototype and broke down how it works. Includes the core function, how I call it on a 2D array, and a JSFiddle to try it (plus a quick note on stack limits for large maps).