View Single Post
  #2 (permalink)  
Old May 19th, 2005, 12:17 AM
AGS AGS is offline
Wrox Technical Editor
Points: 267, Level: 5
Points: 267, Level: 5 Points: 267, Level: 5 Points: 267, Level: 5
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2005
Location: Russia
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
Default

May be I am wrong but I think that example at the beginning of page 31 is not correct. The code is:

var oStringObject1 = new String("yellow");
var oStringObject2 = new String("brick");
var iResult = sTestString.localeCompare("brick");
if(iResult < 0) {
alert(oStringObject1 + " comes before " + oStringObject2);
} else if (iResult > 0) {
alert(oStringObject1 + " comes after " + oStringObject2);
} else {
alert("The two strings are equal");
}

Two string objects were defined, but localeCompare method called for third string object sTestString which was not defined and it is called with a literal parameter "brick". I supposed that definition was just omitted but further there are alerts which are telling us that oStringObject1 "comes before", "comes after" or equal to oStringObject2. But we didn't compare oStringObject1 with oStringObject2, though parameter value of localeCompare is equal to oStringObject2 constructor's parameter.

I think it was supposed to be

var oStringObject1 = new String("yellow");
var oStringObject2 = new String("brick");
var iResult = sStringObject1.localeCompare(oStringObject2);
if(iResult < 0) {
alert(oStringObject1 + " comes before " + oStringObject2);
} else if (iResult > 0) {
alert(oStringObject1 + " comes after " + oStringObject2);
} else {
alert("The two strings are equal");
}

or some other logic was implied.

There are also misprints on the same page (lines 2,3,4,5 and 22) where method localeCompare() is called localCompare().

I am using pdf version of this book in case there is inconsistency in page numbering.

Excuse my poor English.

Best Regards
P.S. I just start reading but I think the book is great.

Reply With Quote