I’m looking to build two functions:
var MyObject = new Object();
MyObject.MyProperty = 1;
function ListenToChange() {
here I want to listen to changes in MyProperty1 and do something when it changes
}
function ThrowEvent () {
here I change the value of MyProperty every 5 seconds
setTimeOut('ThrowEvent', 5000);
}
I looked at the addEventListener property but it looks like it works for DOM objects. I thought of using the ThrowEvent function to change the value of a hidden div and listen for the changes in the value of the hidden with $(‘#HiddenDiv’).change() but I’m wondering if there’s a better way to do it with the addEventListener.
Thanks for your help.
I can infer from your example you’re using jQuery; you could trigger a custom event anytime you change the value of your property: