JS Built-ins
ObjectObject.createintermediate

Object.create() β€” access inherited methods

πŸ“– Usage Example
// Create an object with a specific prototype
const proto = { greet() { return 'hi' } }
const child = Object.create(proto)
child.greet()   // β†’ 'hi'

Use Object.create() to create a new object with a specific prototype, enabling prototype-based inheritance.

Object.create() β€” inherited methods

Objects created with Object.create(proto) can access methods defined on the prototype through the prototype chain.

Challenge: Implement makeGreeter(name) that creates an object with name as an own property, using { greet() { return 'Hello, ' + this.name } } as its prototype.

makeGreeter('Alice').greet() // β†’ 'Hello, Alice'
πŸ’‘ Hints (2)
  • β€’ Define the prototype object with the shared method, then use `Object.create(proto)` to create the instance.
  • β€’ Set the own property (e.g. `name`) directly on the created object.