JSFiddle - React, Tailwind, and code Playground

by HYEONGJINKIM

JavaScript

const Employee = function(name, company, salary) {
    this.name = name || "";       //Public attribute default value is null
    this.company = company || ""; //Public attribute default value is null
    this.salary = salary || 5000; //Public attribute default value is null
    
    // Private method
    const increaseSalary = function() {    	
        this.salary = this.salary + 1000;        
    };

    // Public method
    this.dispalyIncreasedSalary = function() {
        increaseSalary();
        increaseSalary();
        increaseSalary();
        console.log(this.salary);
    };
};

// Create Employee class object
var emp1 = new Employee("John","Pluto",3000);
// Create Employee class object
var emp2 = new Employee("Merry","Pluto",2000);
// Create Employee class object
var emp3 = new Employee("Ren","Pluto",2500);

emp1.dispalyIncreasedSalary();
emp1.dispalyIncreasedSalary();
console.log(emp1.salary);