JSFiddle - React, Tailwind, and code Playground

by Ryan Morris

JavaScript

var me = (function() {
  var trophies = ['red', 'gold', 'swimming'];
  return {
    name: 'Jim Bob',
    age: 105,
    speak: function(words) {
      console.log(this.name, 'says', words);
    },
    viewTrophy: function(i) {
      return trophies[i];
    }
  }
})();

Object.defineProperty(me, 'trophies', {
  enumerable: false
});

try {
  console.log(me.trophies[1]); // should fail
} catch (e) {
  console.assert(e, "Accessing trophies should fail");
}
console.log(me.viewTrophy(1));