โจguard against accidental modifications
an object without prototype.
JS โฉ value โฉ object โฉ create โฉ Object.create() โฉ pure object
Object.create() can be used to protect objects from being modified accidentally.
replit โฉ guard against accidental modifications
// the object to protect
const _protected = {
data: 'DO NOT CHANGE THIS!',
};
// โญ guard against accidental modifications
const inherited = Object.create(_protected);
// โญ this modifies `inherited` itself, not the `protected` one.
inherited.data = 'Hello, World.';
inherited.data, // 'Hello, World.'
_protected.data, // 'DO NOT CHANGE THIS!'Last updated
Was this helpful?