JSFiddle - React, Tailwind, and code Playground

by Andres Mijares

JavaScript

var Person = function(firstName, lastName) {
  this.firstName = firstName;
  this.lastName = lastName;
};

Object.defineProperties(Person.prototype, {
  sayHi : {
    value : function() {
      return "Hi there";
    },
    writable: true,
    enumerable : true
  },
  
  fullName : {
    get : function() {
      return this.firstName + " " + this.lastName;
    },
    configurable : true,
    enumerable : true
  }

});

var createEmployee = function(firstName, lastName, ocupation) {
    
    var employee = new Person(firstName, lastName);
  
    employee.ocupation = ocupation;
  
    /*over-w sayHi*/
  
    var sayHifn = employee.sayHi.bind(employee);
  
    employee.sayHi = function() {
      return sayHifn() + " my name is " + this.firstName;
  
    };
    
    /*over-w fullName*/
 
    var fullName = Object.getOwnPropertyDescriptor(employee, "fullName");
    var fullNameFn = fullName.get.bind(employee);
  
  
    Object.defineProperty(employee, 'fullName', {
      get : function() {
          return fullNameFn() + " this is o-w ";
      }
  
    });
  
    return employee;
  
};

var record = createEmployee('jhon', 'doe', 'eng');
console.log(record);