JSFiddle - React, Tailwind, and code Playground

by yeuem1vannam

HTML

<div id='message'></div>

JavaScript

var MyName;
MyName = (function() {
  // Constructor
  function MyName(ho, ten, country_code) {
    this.firstName = ho;
    this.lastName = ten;
    this.code = country_code;
  }
  // Private methods
  getCountry = function() {
     var countries = {
       'vn': 'Viet Nam',
       'jp': 'Japan'
     };
     return countries[this.code];
  }
  // Public methods
  MyName.prototype.fullName = function() {
    return (
      'My fullname is: ' + this.firstName + ' ' + this.lastName +
      ' and I\'m living in ' + getCountry.apply(this)
    );
  }

  return MyName;
})();
var me = new MyName('Le', 'Phuong', 'vn');

document.getElementById('message').innerHTML = me.fullName();