You
can inherit from an object using ‘Object.setPrototypeOf()’ method.
var organization = { orgName : "ABC Corporation", location : "New Delhi" } class Employee{ constructor(firstName, lastName){ this.firstName = firstName; this.lastName = lastName; } } Object.setPrototypeOf(Employee.prototype, organization); var emp1 = new Employee("Ashwani", "Kumar"); console.log(emp1);
Output
No comments:
Post a Comment