Inheritance in Prototype

by SriSri M

HTML

let user = {
  name: "John",
  surname: "Smith",

  set fullName(value) {
    [this.name, this.surname] = value.split(" ");
  },

  get fullName() {
    return `${this.name} ${this.surname}`;
  }
};

let admin = {
  __proto__: user,
  isAdmin: true
};

JavaScript

let user = {
	fname: "Jhon",
  lname: "Doe",
  
	set fullName(value) {
    [this.fname, this.lname] = value.split(" ");
  }, 
  get fullName() {
  	//return `${this.fname} ${this.lname}`;
    return `${this.fname} ${this.lname}`;
  }
};

let admin = {
  __proto__: user,
	isadmin: true

};
console.log(admin.fullName);