In answer to your main question, there are no generic, built-in event listener that will fire when the value of a variable in javascript changes.
But, if your variable is time related (which a property named currentTime
sounds like it might be, then you could probably use a cleverly set setTimeout()
to know exactly when to check it's value rather than trying to check every 10ms like you're doing now. We'd have to know more about what exactly you're trying to do and what exactly Initialmusic.currentTime
is to know what better to suggest. For example, if you want to know when a particular point in playback is hit, you should be able to register for the start/stop events and just keep your own timer going that should tell you approximately when you get to the desired playback time.
If you are just waiting until the audio completes, then you can just register for the audio event for when it has ended which is the "ended"
event. See here for media events.
In addition, for modern browsers only, if you control the creation of Initialmusic.currentTime
, then you could define a setter function that would trigger a notification to you any time its value is changed. See this code example: https://gist.github.com/eligrey/384583. I don't know if this type of solution would work for an audio host object (I'm guessing it probably would not). You would have to try it in multiple modern browsers to see.