I pass in an array of error messages to parse. An example input would be:
"An item with this x Id already exists.
An item with this y id already exists.
An item with this barcode already exists.
"
That is, the string is literally each line above separated by a \n, with a final \n at the end.
function( msg )
{
alert( "\"" + msg + "\"" );
var aLines = msg.split( /\r?\n+/ );
for ( var i in aLines )
{
if ( !aLines[i] ) { alert( "Error!" ); continue; }
alert( i + ": \"" + aLines[i] + "\"" );
}
}
I split it into lines, and iterate over the lines. At index 3 there is no line and the first conditional triggers. Should that not be an empty line? e.g. ""
Then the loop actually goes one more element to 4, and shows a the contents of a function.
That is I get - five alerts:
0: "An item with this x Id already exists."
1: "An item with this y id already exists."
2: "An item with this barcode already exists."
Error!
The last one is most bizarre:
hasObject: "function(o) {
var l = this.length + 1;
... more lines ...
}
I don't understand what is happening here. Why is it iterating over one more element? And why is the last element a function? And shouldn't offset 3 be an empty string? That is I should not be alerting "Error!" here.