Is there a way for listening for value change of a variable in Javascript (Firefox extension)?
[update]
I am having an array I want to listen. Whenever something is pushed into that array, I want my extension to be notified. I am triggering custom event using jQuery now. I want to know whether anything better than this available within Firefox.
If you control both the code that changes the variable and the code that wants to be notified, implementing the ‘observer’ pattern is the best way to go.
With proxies (experimental), you could avoid having to fire notifications from the code that mutates the array, but I’m not sure it’s worth the hassle.
There might be standard ways to handle this in specific cases (e.g. preferences-related components already provide the observer mechanism for you).