Here is the snippet of code I am working with:
update: function(e,d) {
var element = $(this);
var data = element.data();
var actor = element.find('.actor');
var value = basicdesign.defaultUpdate( e, d, element, true );
var on = templateEngine.map( element.data( 'threshold_value' ), element.data('mapping') );
// value >= threshold
if (value >= on){
var maxcount = data.count;
var interval = data.interval;
var audioWidget = document.getElementById(element.data('id'));
if (audioWidget.paused == true){
if (maxcount && interval) {
var numOfCalls = 0;
audioWidget.play();
var intervalID = setInterval(function () {
audioWidget.play();
numOfCalls = numOfCalls + 1 ;
if (numOfCalls == maxcount-1) clearInterval(intervalID);
if **(value < on)** clearInterval(intervalID);
}, interval);
}
else audioWidget.play();
}
};
// value < then threshold
if (value < on){
var audioWidget = document.getElementById(element.data('id'));
audioWidget.pause();
};
}
I am facing an issue where I cannot use 'value' and 'on' in the setInterval-function. I understand that a closure might be the solution - but how can I implement this?
(This code snippet is from cometvisu (audio.js), an open source visualization tool)
Thank you.