Is it possible to have an event in JS that fires when the value of a certain variable changes? JQuery is accepted.
In my case, I was trying to find out if any library I was including in my project was redefining my window.player
. So, at the begining of my code, I just did:
Object.defineProperty(window, 'player', {
get: () => this._player,
set: v => {
console.log('window.player has been redefined!');
this._player = v;
}
});