// from https://snippet.zone

const target = {}
 
let value = null;
Object.defineProperties(target, {
  magic: {
    get() {
      console.log('- getter called::', value);
      return value;
    },
    set(val) {
      document.body.innerHTML += val + '<br>';
      value = val;
    }
  }
});
 
target.magic = 'xyz';
target.magic = 'snippet';
target.magic = 'zone';
target.magic = '- last value';
 
console.log('getting', target.magic);

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.