Inside my function/object I have
this.StatusMappings = [
{
Range: [Infinity*-1, 50],
Color: 'red',
Text: 'Just getting started - will require considerable time to complete.'
},
{
Range: [50, 70],
Color: 'yellow',
Text: 'Incomplete - major gaps exist and completion will take some time.'
},
{
Range : [70, 90],
Color : 'yellgreen',
Text : 'Partially completed - but some gaps remain which can be completed shortly.'
},
{
Range: [90, Infinity],
Color: 'green',
Text: 'Fully completed - no additional work needed.'
}
];
this.UpdateInfo = function ( $slider, newval )
{
var color = this.StatusMappings.firstOrUndefined(function (map) {
console.log("map.Range = "); console.log(map.Range);//TEST
return map.Range[0] >= newval && map.Range[1] < newval;
});
$slider.closest('.slider').addClass(color);
}
and what's strange is that the first time UpdateInfo
is called, everything goes as expected, whereas the second time I get
Uncaught TypeError: Cannot read property '0' of undefined
Because of my //TEST
I see that it works the first time:
By the way, my helper function firstOrUndefined
is
Array.prototype.firstOrUndefined = function ( unpred )
{
for ( var i in this )
if ( unpred(this[i]) )
return this[i];
}