Object.create()
The `Object.create()` method creates a new object with the specified prototype and properties.
Key concepts
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!Stuck on this one? Talk to Sumit.
Keys: F focus mode · ← → previous / next topic · Esc leave focus