JSFiddle - React, Tailwind, and code Playground

by nocircleno

JavaScript

var Something1 = function() {
    var _public = {};
    var _action = "doing";
    Object.defineProperties(_public, {
        action: {
            get: function() {
                return _action;   
            },
            set: function(value) {
                 _action = value;   
            }
        }
    });
    _public.do = function() {
      console.log("doing it");  
    };
    return _public;
}

var Something2 = function() {
  var _action = "doing";
  Object.defineProperties(this, {
        action: {
            get: function() {
                return _action;   
            },
            set: function(value) {
                 _action = value;   
            }
        }
    });
    this.do = function() {
      console.log("doing it");  
    };
}

var s1 = new Something1();
var s2 = new Something2();
s1.action = "return public";
s2.action = "create on this";
console.log(s1.action, "|", s2.action);