Linked Listening for variable changes in JavaScript
I want to run callback()
only if the value is changed instead of set.
If it is set to the same value as previous one, callback()
is not fired.
If it is set to different value then previous one, it is changed and callback()
is run.
How do I do this? I tried storing it in prevVariable
and currentVariable
, and comparing them with if
statement. But I was wondering if there is a better JS feature that does what I want? The variable I am receiving is from external source that I cannot control and I am currently running it with setTimeout
to get constant update of the currentVariable
.