简体   繁体   中英

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?

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM