Object.create()
Topic 5JavaScript Part 4 (OOP)
Object.create()
Introduction
The `Object.create()` method creates a new object with the specified prototype and properties.
Key Concepts and Definitions
Object.create()
Creates a new object with the specified prototype and properties.
Examples
Object.create() Example:
const proto = {
greet() {
console.log(`Hello, my name is ${this.name}`);
}
};
const person = Object.create(proto);
person.name = 'Alice';
person.greet(); // Hello, my name is AliceUsing Object.create() for Prototype Chain:
const proto = { greet: function () { console.log('Hello!'); } };
const obj = Object.create(proto);
obj.greet(); // Hello!Interview guide discussion
(0)Join the discussion — login to comment and help other developers.
Login to comment