Prototypes & OOPmedium

Object.create & Delegation

Object.create(proto) creates a new object with proto as its [[Prototype]], enabling prototypal inheritance without constructor functions or classes.

Memory anchor

Object.create(parent) is adopting a child who inherits the family name and can ask parents for anything. Object.assign is photocopying someone's homework — you get a copy, but no ongoing relationship.

Expected depth

Object.create(null) creates a truly bare object with no prototype — useful for pure hash maps since there are no inherited properties like toString or hasOwnProperty to interfere. Object.create is the underlying primitive that class extends uses. You can use it to set up delegation chains explicitly: const animal = { speak() {} }; const dog = Object.create(animal); dog.bark = function(){}. Object.assign copies own enumerable properties but does NOT set up the prototype chain.

Deep — senior internals

Object.create with a property descriptor second argument allows fine-grained control: Object.create(proto, { x: { value: 1, writable: false, enumerable: false, configurable: false } }). This is how many framework internals create non-enumerable, non-writable slots. Differential inheritance (OLOO — Objects Linked to Other Objects, coined by Kyle Simpson) argues that object delegation via Object.create is a more idiomatic JS pattern than pseudo-classical inheritance with classes, since it directly uses the prototype mechanism rather than emulating class-based OOP.

🎤Interview-ready answer

Object.create(proto) creates an object that delegates to proto via the prototype chain without needing a constructor. It is the most explicit way to set up prototype delegation and is what class extends compiles to under the hood. Object.create(null) is the correct choice for pure dictionary objects since it avoids prototype property collisions.

Common trap

Object.assign(target, source) does a shallow copy of own enumerable properties — it does NOT set up prototype delegation. const child = Object.assign({}, parent) creates an object with copied own properties but child.__proto__ is still Object.prototype, not parent. Use Object.create(parent) for delegation.

Related concepts