The js confirm from js in the browser stops the js execution. When you're using a "custom confirm" (a js library confirm) the code below the "custom confirm" keeps executing and that's the reason why you obtain the message there, as it keeps executing and you have variables defined inside the function, when js tries to use them, it shows the "undefinned variable".
You have to insert all the code in the alertfy to make sure it works correctly (I haven't checked code below, so, just take it carefully):
alertify.confirm(confirmMSG, function (e) {
if (e) {
// user clicked "ok"
user_confirm=true;
console.log("user clicked ok");
for (var i=0;i<_limits.length;i++){
if(IsNumeric(parseInt(_limits[i]))){
n=this.msgs[i].indexOf(this.limits[i].toString());
this.limits[i]=_limits[i];
this.msgs[i]=this.msgs[i].slice(0,n)+this.limits[i];
changed_flag=true;
}
// clean past alerts in case of change limits.
if(changed_flag) {
this.cleanPastAlerts();
}
}
} else {
// user clicked "cancel"
user_confirm=false;
console.log("user clicked cancel");
}
});
if(DEBUG_MODE)
console.log("alarms update: upperLimit:"+this.limits[0]+" lowerLimit:"+this.limits[1]);