我期待看到:
设置
得到
15
有人可以向我解释为什么这段代码不起作用吗?谢谢
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);