I tried to execute this small part of code in my browser console:
a = {b: 1}
Object.defineProperty(a, 'b', { get: function() { console.log(5); } })
c = a.b
c
c
Everytime i used to call 'c' varaible, i am not getting console.log(5) to be executed. That means my getter is not calling. I think that might be because i am not calling a.b directly but using c variable instead. Can someone confirm/reject my thoughts ? Also how can i make it call getter everytime i am calling 'c' ?
Thanks.
a.bassigned toc. That is when your getter in invoked. And once the get value is assigned toc.cbehaves like any other variable.