JSFiddle - React, Tailwind, and code Playground
by alek1688
JavaScript
var Test = (function () {
return function Test() {
var $this = this,
definition = {
foo: {
get: function () { return $this.getProperty("foo"); },
set: function (value) { $this.setProperty("foo", value); },
enumerable: false,
configurable: false
},
bar: {
get: function () { return $this.getProperty("bar"); },
set: function (value) { $this.setProperty("bar", value); },
enumerable: false,
configurable: false
}
},
storage = {};
Object.defineProperties(this, definition);
this.getProperty = function (name) {
console.log("get was definitely called!");
return storage[name];
};
this.setProperty = function (name, value) {
console.log("set was definitely called!");
storage[name] = value;
};
};
})();
var test = new Test();
//undefined
test.foo = "Hello World";
//set was definitely called!
//"Hello World"
test.bar = 3;
//set was definitely called!
//3
test.foo;
//get was definitely called!
//"Hello World"
test.bar;
//get was definitely called!
//3