This might solve your issue
var errorval = "Not set";
var rules = {
firstRule : {
name : 'example',
getMessage : function() {
return 'Needs to be '+errorval+' characters long';
}
}
}
$('.button').on('click', function(){
for(var foo in bar) {
$.each(foo, function(){
errorval = 3;
// ALERTS "Needs to be Not set characters long"
alert(rules.firstRule.getMessage());
});
}
});
Instead of a string property, you call the getMessage method which returns a string based on the current value of errorval