JSFiddle - React, Tailwind, and code Playground

by Ace Tributon

HTML

<p id='demo'>

</p>

JavaScript

function Person(age, weight) {
    /*this.age = age;
    this.weight = weight;
    this.getInfo = function() {
        return "I am " + this.age + " years old " +
        "and weighs " + this.weight +" kilo.";
    }*/
    //return edition
		return {
			getInfo(){
        return "I am " + age + " years old " +
        "and weighs " + weight +" kilo.";
    	}
		}

}
function Employee(age, weight, salary) {
    this.salary = salary;
    this.age = age;
    this.weight = weight;
    this.getInfo = function() {
        return "I am " + this.age + " years old " +
        "and weighs " + this.weight +" kilo " +
        "and earns " + this.salary + " dollar.";
    }
		this.rich=this.salary>=100000?'I am rich':'I am not rich';
}

Employee.prototype = new Person;
Employee.prototype.constructor = Employee;
  // The argument, 'obj', can be of any kind
  // which method, getInfo(), to be executed depend on the object
  // that 'obj' refer to.

function showInfo(obj,method) {
    demo.innerHTML+=(typeof method==='function'?obj[method]() + "<br>":obj[method]+ "<br>");
}

var person = Person(50,90);
var employee = new Employee(43,80,50000);
showInfo(person,'age');
showInfo(employee,'rich');