defining a property late
show that object properties can be set
by Gerald Gillespie
JavaScript
class MyClass {
constructor(value) {
this.simple = value;
this.aprivateprop = {
'a': value
};
Object.defineProperties(this, {
'aprivateprop': {
get: ()=>{ return 'eff u'},
enumerable: false
},
'prop': {
value: Object.assign({}, this.aprivateprop),
enumerable: true,
writable: false
},
'prop2' : {
value : 'value2'
}
});
}
lateDefine(){
Object.defineProperty(this, 'lateprop',{
value : Object.assign({},this.aprivateprop)
});
}
}
const myclass = new MyClass('A');
console.log(myclass, myclass.prop, myclass.arivateprop, myclass.prop2 );
myclass.lateDefine();
console.log(myclass.lateprop)