JSFiddle - React, Tailwind, and code Playground
by rgthree
JavaScript
var myObj = {};
function CreateSimpleProperty(propertyName) {
Object.defineProperty(myObj, propertyName, {
set: function (aVal) {
this['_'+propertyName] = aVal;
console.log("Setting");
},
get: function () {
console.log("Getting");
return this['_'+propertyName];
}
});
}
CreateSimpleProperty("TEST");
myObj.TEST = 15;
console.log(myObj.TEST);