Which fix removes the subtle bug?
const merged = Object.assign({}, base);
merged.opts.debug = true;
console.log(base.opts.debug);
- Copy deeply with
structuredClone(base) - Copy deeply with
Object.entries(base) - Call
Object.assignwith two sources - Freeze
basebefore the assignment
Object.assign copies one level, so
Play Problem Solving ▸
opts is shared and the write leaks into base.