I have a global variable and its type is String:
window.my_global_var = 'string';
It might be changed by some external-loaded JavaScript files or an AJAX request. So I want to watch it and invoke a callback when it's updated.
I searched a while but found Object.observe is already deprecated. I found an answer but it is better used to observe an object, not a String window.variable.
The worst approach would be using a setInterval
to watch it but I guess it's too stupid.
Is there any good way to do this?