I declare a variable which gets it’s value through another event out of a select-box. Since there are different events which change the variable (lets name it z), I want to get informed when the variable gets changed.
So my question is: What is the best way to get informed when a variable gets changed?
z.change(function(){}); throws an error.
Are there ways to do this without a hidden input-field or other helpers like that?
It’s not really possible, but some browsers support getters and setters, and with them you could implement something that called an external function when the value is chanced. If you want this to work in all browsers, then you could go the old fashioned way of doing this:
And then always remember to only access the property through these functions.