Using Object.create to Establish Prototype Relationship in Javascript


Create a new object with a specified prototype object and properties.

Source Code

let personProto = {
  greet() {
    console.log(`Hello, ${this.name}`);
  }
};
let person = Object.create(personProto);
person.name = 'John';
person.greet(); // Hello, John
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments