JS Built-ins
Prototypesbeginner

Prototypes β€” Object.create with prototype

πŸ“– Usage Example
const proto = { greet() { return 'hello'; } };
const obj = Object.create(proto);
obj.greet(); // 'hello'

Object.create() creates an object with a specified prototype for inherited methods.

Creating Objects with Specific Prototypes

Object.create(proto) creates a new object with the specified prototype object. This is the standard way to set up prototype inheritance without using constructor functions.

Challenge: Use Object.create() to create objects that inherit methods from a custom prototype.

πŸ’‘ Hints (2)
  • β€’ Object.create(proto) sets up the prototype chain
  • β€’ Properties added after creation are own properties