fromEntries and Object Spread
Rebuild an object from entries, and merge objects with spread.
Object.fromEntries is the reverse of entries.
Object spread { ...a, ...b } shallow-merges; later keys win.
Use that for defaults + per-instance overrides — keep a base
options object, then { ...base, origin: "right", delay: 500 } for
one call without mutating the shared defaults.
Defaults + patch
Merged / rebuilt
Important JavaScript
const defaults = { theme: "light", pageSize: 10, notifications: true };
const patch = { theme: "dark", pageSize: 25 };
const merged = { ...defaults, ...patch };
// { theme: "dark", pageSize: 25, notifications: true }
// later spread wins on conflicting keys
// Same idea for animation / library options:
const base = { distance: "50px", duration: 1000, origin: "bottom" };
const asideOpts = { ...base, origin: "right", delay: 500 };
const pairs = Object.entries(merged);
const again = Object.fromEntries(pairs);
// same plain object shape
const tweaked = Object.fromEntries(
pairs.map(([key, value]) => {
if (key === "pageSize") {
return [key, Number(value)];
}
return [key, value];
})
);