Working Without proto
Modern JavaScript provides clean methods for prototype management:
| Method | What It Does |
|---|---|
Object.create(proto) | Creates a new empty object with proto as its [[Prototype]] |
Object.getPrototypeOf(obj) | Returns the [[Prototype]] of obj |
Object.setPrototypeOf(obj, proto) | Changes the [[Prototype]] of an existing object |
let animal = { eats: true };
let rabbit = Object.create(animal);
rabbit.name = 'White Rabbit';
console.log(rabbit.eats); // true — inherited
console.log(Object.getPrototypeOf(rabbit) === animal); // true
The " Pure Dictionary " Pattern
// No inherited properties — safe for arbitrary keys
const safeMap = Object.create(null);
safeMap['toString'] = 'my value'; // No conflict with Object.prototype!
Tip
Object.create(null) creates a completely " clean " object with no prototype — perfect for safe key-value storage.