Use Object.watch () for an "independent" variable?

Maybe I am missing something serious, but is there a way to use Object.watch () for variables that exist independently of objects?

I am a bit js noob and cannot find any global object that my variable is bound to.

(Also, just using this for debugging, so the fact that it is only supported on Mozilla browsers is not a problem.)

+4
source share
1 answer

The global scope in the browser is actually a window object, so if your variable is a global variable, it is actually bound to the window object. That way you can access it as window.variableName just like just variableName . And so you should be able to say:

 window.watch('variableName', callback); 
+3
source

All Articles