I am expecting to see:
Setting
Getting
15
Can someone please explain to me why this code doesn't work? thanks
var myObj = new 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");
Overlay.TEST = 15;
console.log(Overlay.TEST);