Assume the following constructor function:
function MyClass(){
let myProperty= false;
Object.defineProperty(this, 'myProperty', {
get: function(){
return myProperty
}
});
}
I am now trying to access 'myProperty' in a 'start' prototype method:
MyClass.prototype.start = () => {
console.log('myProperty---> ' + this.myProperty)
}
But this does not work:
let x = new MyClass
//undefined
x.start()
//'myProperty---> 'undefined
/*myProperty should be false*/
What am I doing wrong? It's almost as if the 'Object.defineProperty' method didn't do it's job of making 'myProperty' public....
(ALL CODE RUNNING IN GOOGLE CHROME CONSOLE)