Search code examples
javascriptangularjswatchobservers

how to observe if variable changes value in javascript?


I know of Object.observe() and Object.prototype.watch() but those are not very widely suported features (unfortunatly), meanwhile I know AngularJS does something to watch changes on objects...

I'm trying to create an script with this capability but much much lighter than Angular. First I remembered that I saw somewhere in this site that object properties could have (or had) set and get methods. That sounded strange to me maybe my memory is weak.

Am I in the right direction? Any enlightment on how to do this?


Solution

  • There are a few polyfils for observing variable value, I've been using this one

    https://gist.github.com/eligrey/384583