JavaScript: The Definitive Guide

Errata for JavaScript: The Definitive Guide

Submit your own errata for this product.

The errata list is a list of errors and their corrections that were found after the product was released.

The following errata were submitted by our customers and have not yet been approved or disproved by the author or editor. They solely represent the opinion of the customer.

Color Key: Serious Technical Mistake Minor Technical Mistake Language or formatting error Typo Question Note Update

Version Location Description Submitted By Date Submitted
PDF Page 74

Is printed var data = [7,8,9]; but it must be var data = ["0","1","2"];

Said Fayad  Aug 07, 2016 
PDF Page 6
Final code block, above first paragraph

The code false == (x > y) (x == 2) && (y == 3) (x > 3) || (y < 3) will result in TypeErrors. `(x == 2)` and `(y ==3)` will be evaluated as functions without semicolons (if executed from a file). See: I don't know if it's a mistake. The code examples may not have the intention of being executed in a file. I just thought I'd send something in, see if it actually was a mistake or not

Ed Flanagan  Dec 10, 2015 
Printed Page 144
7.3 Sparse Arrays

Section 7.3 example var a1 = [,,,]; // This array is [undefined, undefined, undefined] var a2 = new Array(3); // This array has no values at all 0 in a1 // => true: a1 has an element with index 0 0 in a2 // => false: a2 has no element with index 0 0 in a1 actually evaluates to false. It is not true. Tested in Mozilla Scratchpad.

Anonymous  Jun 06, 2015 
Printed Page 137
1st paragraph

These examples assume that the array is dense and that all elements contain valid data. If this is not the case, you should test the array elements before using them. If you want to exclude null, undefined, and nonexistent elements, you can write this: for(var i = 0; i < a.length; i++) { if (!a[i]) continue; // Skip null, undefined, and nonexistent elements // loop body here } Above logic will not only skip null, undefined or nonexistent, it will also skip elements that evaluate to false (such as number 0)

Anonymous  Apr 17, 2015 
PDF Page 375
Second before last paragraph

The word HTTP was used instead of HTML.

Anonymous  Apr 14, 2015 
PDF Page 367
3rd paragraph

The name of the field of the document object is scripts, not "<scripts>".

Rodrigo Fernandes da Costa  Apr 13, 2015 
Other Digital Version 348
~4th paragraph

The book references the [cookieEnabled] property as if it were a method, ie: cookiesEnabled(). In addition, it references the property as if it were plural (cookies) rather than singular (cookie). The proper reference would be: navigator.cookieEnabled, not: navigator.cookiesEnabled()

Aaron MArtone  Aug 31, 2014 
Other Digital Version 202
4th paragraph, under "Constructors and Class Identity"

Using the Kindle Version of this book. It states on "Page 202 of 1018 (Location 10025 of 50992)" under the subheading "Constructors and Class Identity": "Even through constructors are not as fundamental as prototypes..." The typo is the word "through" for "though".

Aaron Martone  Aug 26, 2014 
Printed Page 84
First code example

var a = [1,2,3]; // Start with an array delete a[2]; // Delete the last element of the array a.length // => 2: array only has two elements now When used with arrays, delete only sets the element to undefined and doesn't change the array length. Therefore a.length remains at 3. "Note that a deleted property or array element is not merely set to undefined..." should thus also be "Note that a deleted property is not merely set to undefined..."

Anonymous  Jul 04, 2014 
PDF Page 51
3.8.3 Object to Primitive Conversions, last paragraph

I think the word "string-to-primitive" in this case is wrong: "+, ==, != and the relational operators are the only ones that perform this special kind of string-to-primitive conversions." Should be: "+, ==, != and the relational operators are the only ones that perform this special kind of object-to-primitive conversions." (you should read the entire section 3.8.3 to understand what I mean)

Héliton Nordt  Feb 27, 2014 
PDF Page 51
3.8.3 Object to Primitive Conversions, last paragraph

I think the word "string-to-primitive" in this case is wrong: "+, ==, != and the relational operators are the only ones that perform this special kind of string-to-primitive conversions." Should be: "+, ==, != and the relational operators are the only ones that perform this special kind of string-to-primitive conversions." (you should read the entire section 3.8.3 to understand what I mean)

Héliton Nordt  Feb 27, 2014 
PDF Page 60
4.4 Property Access Expressions

var o = {x:1,y:{z:3}}; var a = [o,4,[5,6]]; here is mistake a[0].x // => 1: property x of expression a[0]

Anonymous  Dec 01, 2013 
Printed Page 194
code following first paragraph

In the definition of the higher-order mapper function you write map(a,f) //not defined instead of

Anonymous  Jul 09, 2013 
Printed Page 226
1st paragraph

In the first sentence you use the word 'now' instead of 'not'. It should read: '... and not allowing the important state variables to be read or written directly'.

Don Woodlock  Jun 05, 2013 
PDF Page 127

The second line in the code example for function merge(o, p) reads: if (o.hasOwnProperty[prop]) continue; // Except those already in o. it should read: if (o.hasOwnProperty(prop)) continue; // Except those already in o.

Johannes Choo  May 30, 2013 
Printed Page 611
Array.unshift > Description

Second sentence reads: "The first argument to shift() becomes..." Should read: "The first argument to unshift() becomes..."

Tom Kumpf  Jan 25, 2013 
Printed Page 174
end of code example

The book recommends using "args.to_start || 0" in order to process an optional parameter. This produces an error in Firefox and seems to be bad practice. If the parameter was passed but evaluates to false it won't be used. See explanation of what I mean here:

Anonymous  Jun 06, 2012 
PDF Page 738
Array.splice example

The sample output seems to have been based on a different original source array, so the actual output values differ from what the book indicates. When I try the second example with Node.js, I get the following: $ node > var a = [1,2,3,4,5,6,7,8] undefined > a [ 1, 2, 3, 4, 5, 6, 7, 8 ] > a.splice(1,2); [ 2, 3 ] > a [ 1, 4, 5, 6, 7, 8 ]

Al Wold  Apr 28, 2012 
Printed, PDF Page 68
bottom of page

The book has the logic of post-increment operator backwards. The book reads: "var i = 1, j = i++; // i is 2, j is 1" It should read: "var i = 1, j = i++ // i is 1, j is 2"

Anonymous  Mar 19, 2012 
PDF Page 771
Error.toString() Synopsis

Remove space from "error. toString()"

roscoe1  Jul 22, 2011 
PDF Page 770
Error Examples

In the sentence fragment, "And if you catch an exception, you might display its to the user with code like the following", change "its" to "it" or specify what is displayed.

roscoe1  Jul 22, 2011 
PDF Page 766
decodeURIComponent() Synopsis

Change decodeURI(s) to decodeURIComponent(s)

roscoe1  Jul 22, 2011 
PDF Page 757
Date.setUTCFullYear() Synopsis

Change date.setSeconds(seconds, millis) to date.setUTCFullYear(year, month)

roscoe1  Jul 22, 2011 
PDF Page 725
Array.filter() Synopsis

Change syntax for to syntax for array.filter()

roscoe1  Jul 22, 2011 
Safari Books Online 4.4
(Safari Books Section 4.4) 3rd paragraph

of -> or Current: This second expression specifies the name of the desired property of the index of the desired array element. Proposed: This second expression specifies the name of the desired property or the index of the desired array element.

Adam Tolley  Jun 24, 2011 
Printed Page 902

The text says that Table.insertRow(index) throws a DOMException if index is negative, but the DOM2 HTML spec says that a value of -1 for index causes the new row to be appended to the table. (Firefox and Opera both treat -1 that way; I haven't tested other browsers.) The same applies to TableRow.insertCell() on page 904.

cchittle  Mar 28, 2011 
Printed Page 375

In example 16-4 (tooltip.js), the comments in the CSS are not formatted correctly. This is probably because they cannot be nested in JavaScript, but confusing to the reader who tries to uncomment the example CSS class definitions and use them. There should be a note that all the "* /" must be changed to "*/ to work correctly. Same applies to the downloadable examples.

P Sherwood  Jan 30, 2011 
Other Digital Version 999

Several typos in the examples have been reported and fixed in the book, but not in the example downloads. For instance, in example 14-2 "Element" is misspelled "Elemnet". All examples should be corrected as is the book. BTW, your errata table shows corrections made in 2007 and 2008, and the corrections have been made in my printed 5th edition book, whose printing history is listed as August 2006.

P Sherwood  Jan 29, 2011 
Printed Page 201
1st paragraph

The characters '=', '!', and ':' do not have special meaning in a regex.

Jake  Nov 19, 2010 
Printed Page 210
Paragraph continued from previous page

Where the text says "For a regular expression r and string s that does not have the g flag set,...", shouldn't it be "For a string s and regular expression r that does not have the g flag set,..."?

Timothy W. Fortune  Sep 24, 2010 
Printed Page 517
in example with class

In that class in constructor we specify the expression to evaluate and than call call the "getNodes" or "getNode" function. In the instance of the class we store a link to XPathExpression object that we created by "document.createExpression()" function. In "getNodes" or "getNode" function we specify a context from which we want to evaluate the expression. The problem is that if this context is different from "document" object from which we call "createExpression()" function, we have an exception with a message "Node cannot be used in a document other than the one in which it was created". One of solutions to this problem is to store a link to context in our "XPathExpression" class and in functions "getNodes" and "getNode" call "evaluate()" function on him.

Anonymous  May 24, 2010 
Printed Page 187
Section 10.1.2

In code sample Ex10-2, the 'construct' property of the object passed into the 'define' function should be the 'init' property.

Anonymous  May 05, 2010 
Printed Page 880

Book: "The most deeply nested Document node" Should read: "The most deeply nested Element node"

Axel Dahmen  Mar 12, 2010 
Printed Page 260
2nd paragraph

Book: "If Microsoft were to define an addEventHandler() method ..." Should read: "If Microsoft were to define an addEventListener() method ..."

Axel Dahmen  Mar 12, 2010 
Printed Page 823
properties offsetHeight, offsetWidth, scrollHeight, scrollWidth

I believe that the description of left-mentioned properties is ambiguous. It doesn't get clear on clipped (CSS overflow:hidden) content. I would write: "int offsetHeight, offsetWidth The height and width, in pixels, of the element's rendered content (only the visible portion of a clipping region), including the element's CSS padding, border and scrollbars, but not its margin." "int scrollHeight, scrollWidth Computed height and width, in pixels, of an element. This includes portions being clipped by a clipping region, but no scrollbars."

Axel Dahmen  Mar 12, 2010 
Printed Page 537
example 22.4

Agree to the other comment on this issue. I had the same problem in Firefox 3.6. The callback function must havbe been defined in code before possibly called. Apparently parsing a JavaScript file is not a 2-pass process but a 1-pass process.

Axel Dahmen  Mar 12, 2010 
Printed Page 843

Book: "the onclick handler is also triggered when the user activates the element using keyboard traversal." Should read: "... using a dedicated trigger key on the keyboard. Most modern browsers are using the [SPACE] key to trigger the onclick event." ...otherwise the event's name was "onfocus" ;)

Axel Dahmen  Mar 12, 2010 
Printed Page 840
Input element names

Book: "name=value1,value2,...,valuen" Should read: "name=value1&name=value2&...&name=valuen"

Axel Dahmen  Mar 12, 2010 
Printed Page 149
2nd bullet

The text states that "a function literal or nested function that appears within a loop or function is not recompiled each time it is encountered. Nor is a different function object created each time a function literal is encountered." The latter statement needs clarification. For example, consider: var a = []; for(var i = 0; i < 2; i++) { a[i] = (function() {}); } alert(a[0]===a[1]); // displays false This code demonstrates that a new function object is created for the function literal in the loop on each iteration of the loop. So, under what conditions is a new function object not created for the same literal?

Anonymous  Mar 07, 2010 
Printed Page 138
function check(args)

Fifth edition, page 138, the second line in function check(args) should be: var expected=arguments.callee.length; and not args.callee.length;

Kedar Mhaswade  Jan 05, 2010 
Printed Page 93
5th Paragraph

The last line in this paragraph says: ...this line enumerates the array "properties", 0, 1, and 2: ... It should be: ...this line enumerates the array "properties", "0", "1", and "2": (I am saying this because I think the names of the object/array properties are always strings).

Kedar Mhaswade  Jan 02, 2010 
Printed Page 27
3rd Paragraph

David, It's hard to term this an error like this form says. I just wanted to first of all congratulate you on describing the escape sequences so well. You have done a great job of explaining the "world's most misunderstood language (as Crockford calls it)". One thing I thought could be added to the description is multiple applications of the '\' character. It was not evident from the contents on page 26-27 what would happen if I do document.write('is tab \\\t ?'); It clearly is \ followed by a tab character i.e. once an escape sequence is interpreted it is not interpreted again (i.e. its interpretation is not recursive). Do you think this is a valid request? Best Regards, Kedar

Kedar Mhaswade  Dec 29, 2009 
Printed Page 479
paragraph just before section 20.1.1

I see in the Errata that this paragraph was added. I am confused by these <literal> tags. Is it possible that they were meant to be stripped out of the actual printed version? Thanks, any response would be appreciated.

Anonymous  Dec 08, 2009 
Printed Page 299
1st paragraph

It was never standardized, and IE 5 and later adopted the W3C... should be: It was never standardized, and IE 5 later adopted the W3C...

Anonymous  Nov 12, 2009 
Other Digital Version n/a
1.5. Exploring JavaScript

javascript:x = 3; (x > 5)? "x is less": "x is greater" should be: javascript:x = 3; (x > 5)? "x is greater" : "x is less"

Bo  Nov 09, 2009 
Printed Page 120
particularly on prototype topic

suggestion: your discussion on "object" , prototype could be improved. i feel there should be a distinction between a type (class/ definition of) and an instance of the type. Your use of the term "object" is ambiguous and confusing, particularly in discussion of the topic prototype.

mario  Nov 07, 2009 
Printed Page 610

Since, "a.splice(4); // Returns [5,6,7,8]; a is [1,2,3,4]" was removed from text of the printed copy I recently purchased, the results in the following operations are incorrect. var a = [1,2,3,4,5,6,7,8] a.splice(1,2); // Returns [2,3]; a is [1,4] a.splice(1,1); // Returns [4]; a is [1] a.splice(1,0,2,3); // Returns []; a is [1 2 3] should be: var a = [1,2,3,4,5,6,7,8]; // was missing semicolon a.splice(1,2); // Returns [2,3]; a is [1,4,5,6,7,8] a.splice(1,1); // Returns [4]; a is [1,5,6,7,8] a.splice(1,0,2,3); // Returns []; a is [1,2,3,5,6,7,8]

Boyd Brown  Sep 24, 2009 
Printed Page 120
2nd paragraph under 7.7.6 splice()

"If this second argument is omitted, all array elements from the start element to the end of the array are removed." probably should read: "If this second argument is omitted, inconsistent behavior across browser implementations will occur. Use 0 to specify no deletions and the length method to delete all array elements from start element to end of array." In the example following the paragraph: a.splice(4); should be: a.splice(4,a.length); // works with Firefox & IE, but maybe not safe? or a.splice(4,(a.length-4); Anyway, paragraph needs to be corrected.

Boyd Brown  Sep 24, 2009 
Printed Page 463,464,465
beginning of code block

The code block on pages 463,464 and 465 begin (erroneously) with: /** * This is the Cookie() constructor function. which is taken from a valid comment block (within the second code block) on page 462. This appears to be a formatting problem, but itn will also cause bad code. Because the comment blocks are unterminated, in the real world™ they will comment out the rest of the code until a comment termination appears.

Anonymous  Sep 07, 2009 
Printed Page 201
First Paragraph

The hyphen "-" is wrongly omitted from the list of punctuation characters that have special meanings in regular expressions.

Jeff Creamer  Aug 22, 2009 
Printed Page 131
Start of example code, first line of commented part

//Copy length elements of the array from to the array to. Was confused by this at first not realizing that "from" and "to" were array names. Maybe italicize them to indicate that they are names?

Anonymous  Jul 23, 2009 
Printed Page 151
3rd paragraph

5th edition The third paragraph states that, if a constructor function returns an object this object becomes the value of the new expression instead of the newly created object, which is discarded. It's the other way round. The returned object is discarded and the newly created object is always returned. Regards Andreas

Anonymous  May 21, 2009 
Printed Page 902
Throws paragraph

In the Throws section, it should say "if index is less than -1", rather than "if index is less than 0".

Anonymous  May 02, 2009 
Printed Page 417-418
417: last 3 lines; 418: top line

The comments in the example code on p417 imply that an element always has a "document" property, then the code on 418 goes on to make that assumption. But nowhere (that I can find) in the text of the book is this documented. It seems that an undocumented feature of IE is being employed, since there is no "document" property attached to an element in FF according to my test. I realise the example is specifically targeted at the IE browser, but it would be much more helpful if attention was drawn to the undocumented nature of this usage (if that is indeed the case). Note that the "document" property of an element is not mentioned in the Reference section either, causing further confusion, since in general the Reference section identifies browser-specific implementations.

Clark Pearson  Apr 06, 2009 
Printed Page 15,18

Unicode is not a 16-bit encoding.

Anonymous  Apr 03, 2009 
Printed Page 417
example 17-2 in the middle

Nothing but praise for this excellent book. I found a nasty little error in the book: for instance, when adding an onclick event to a <a> tag, using Handler.Add(aLink,"click",myhandler) does not return false or true when the link is clicked, so it is not possible to stop the link performing the default action. when the line,event); is changed into return,event); it works as expected. kind regards,

b.koeman  Feb 07, 2009 
Printed Page 610
Example at top of page

The example as printed is as follows: var a = [1,2,3,4,5,6,7,8] a.splice(1,2); // Returns [2,3]; a is [1,4] a.splice(1,1); // Returns [4]; a is [1] a.splice(1,0,2,3); //Returns []; a is [1 2 3] The correct results are as follows: var a = [1,2,3,4,5,6,7,8] a.splice(1,2); // Returns [2,3]; a is [1,4,5,6,7,8] a.splice(1,1); // Returns [4]; a is [1,5,6,7,8] a.splice(1,0,2,3); // Returns []; a is [1,2,3,5,6,7,8]

Robert Gage  Feb 02, 2009 
Printed Page 168-169
7th line after the end of Example 9-3

I'm looking at the 9/08 printing. My issue is with the passage on p.169 beginning "You must explicitly create this prototype object as an instance of the superclass, ..." and ending at the end of that paragraph. The text actually seems to describe what's happening here : but at the bottom of p.168 the heir () function is used to circumvent the need for the constructor call. Both are correct (I think) but it's incredibly confusing for a newbie like me. It does look rather like a case of the code having been updated without a change in the comments.

Simon R Hughes  Jan 22, 2009 
Printed Page 15-9

I think I found a little bug in one of the examples in the book: example 15-9. A logging facility for client-side JavaScript. It should not work for IE because it needs a tbody element in a table element. You can find the elements in the dom tree by IE Developer toolbar but you cannot see anything of a table in the page. Thank you for this GREAT book!!!

Anonymous  Dec 18, 2008 
Printed Page 518

In Firefox 3.0.4, the XML.XPathExpression.getNodes function throws the following error: "Node cannot be used in a document other than the one in which it was created." This is apparently due to tightening of security restrictions in the new version of the browser.

Brannan Cass  Dec 17, 2008 
Printed Page 15
1st paragraph, second sentence

Incorrect details in description of Unicode: 1. Unicode is a character set but it is not generally used as an encoding. UTF-8 (and UTF-16) are commonly used encodings that can represent any Unicode character. The use of the Unicode number for a character in JavaScript literals such as "\u03c0" is an escape sequence, not an encoding. 2. Unicode has grown over time. It's no longer 16 bits, although that's plenty good for most purposes. Code points now go up to 0x10FFFF, which requires 21 bits. FWIW, Java supports all these characters as of (I think) the 5.0 JDK, which means a single Unicode character may be represented in 2 16 bit Java chars. See:

Anonymous  Dec 02, 2008 
Printed Page 114
6th paragraph

var undefs = [,,]; // An array with two elements, both undefined This has been previously reported (by me?!), but not quite correctly. The number of elements created appears to be browser-dependent. IE7 for Windows creates three elements, apparently inferring an element following the trailing comma. FF2 for Windows creates 2...probably because it seems to ignore a final trailing comma in a list (similar behaviour to Perl).

Anonymous  Oct 26, 2008 
Printed Page 11
2nd paragraph

when looking for the JavaScript console under the Tools menu in Firefox, its labeled as Error Console. I was a little confused by that.

Anonymous  Sep 04, 2008 
Printed Page 935
4th paragraph, item 5

Last sentence of item #5: Now reads: "If so, use getResponseHeader() or getResponseHeaders() . . ." Should read, "If so, use getResponseHeader() or getAllResponseHeaders() . . ."

Anonymous  Aug 28, 2008 
Printed Page 120
first paragraph

Concerning Array.slice(), in the second full sentence on this page, the book says "If either argument is negative, it specifies an array element relative to the last element in the array." It goes on to say, correctly but in apparent contradiction, "An argument of -1, for example, specifies the last element in the array...". Suggested revision: "If either argument is negative, it specifies an array element relative to the END OF the array." (instead of, "the last element in") I love this book. Hope Mr. Flanagan understands what a compliment he is receiving when readers submit errata. People don't want to help fix something unless they really like it :).

Anonymous  Aug 16, 2008 
Printed Page 462
near bottom

For problem previously noted (IE too, not just Firefox) my vote would be: var cookies = allcookies.split('; ');

Anonymous  Jul 07, 2008 
Printed Page 386
Comments for function deleteRule

In the comment for the Stylesheet.prototype.deleteRule function, the fourth line should refer to the "s" parameter, not the "n" parameter.

Anonymous  Jul 03, 2008 
Printed Page 382
Last paragraph

In the second sentence of the last paragraph "The HTML DOM Level 2 standard defines a disabled property for both <link> and <script> elements." the tag <script> should be the tag <style>.

Anonymous  Jul 03, 2008 
Printed Page 140
Example 8-3. Object utility functions (continued)

The code in the example 8-3, is incorrect. Instead of: for (p in from) { if (!p in to) to[p] = from[p]; } It should be: for (p in from) { if (!(p in to)) to[p] = from[p]; } Notice the extra brackets in the if statement.

Anonymous  Jun 11, 2008 
Printed Page 1

Printed Page 36

"var a = new Array(10); creates a new array with 10 undefined elements. " Would that not be 11 elements?

Printed Page 49
Section 4.1, safari

In Java 1.5 with autoboxing the following code is legal, Object o = null; o = 10; o = "hey"; Autoboxing is overlooked in section 4.1, Variable Typing

Printed Page 52
4.3.1 No Block Scope, 2nd paragraph and concept in general

The second code example that follows "The rule that all variables declared... can cause surprising results. The following code illustrates this:" var scope = "global"; function f() { alert(scope); // Displays "undefined", not "global" ... } f(); --------------------- This code does in fact display the word "global" in an alert window (IE7, FF2). It seems to me that if you couldn't reference variables outside functions by name you wouldn't actually have 'global' variables...?

Printed Page 52
At the bottom of the page

There is in fact NO ERROR in the last code segment on page 52 even though the "Unconfirmed error reports and comments from readers" shows that someone has claimed otherwise. I've tested the example as given in the book and the behaviour exactly matches the one indicated in the code comments and the description around the example code.

Printed Page 54
3rd paragraph from bottom of page, last sentence

"there just happens to be two references to it." Change "happens" to "happen"

Printed Page 65
1st full paragraph

[ For example, the following code sets both i and j to 2: i = 1; j = ++i; But these lines set i to 2 and j to 1: i = 1; j = i++; ] No, the first two lines set i to 1 and j to 2. The second two lines set both i and j to 1.

Printed Page 65,140
upper half

I've been checking the page "Unconfirmed error reports and comments from readers". Apart from the one remark I sent earlier here are my other findings: The errata claims that the text on the page 65 of the book: For example, the following code sets both i and j to 2: i = 1; j = ++i; But these lines set i to 2 and j to 1: i = 1; j = i++; is in error. It isn't. Instead it correctly describes how these expressions behave. The behavior is the same in C/C++, Java, JavaScript and I'm sure in some other languages too.

Printed Page 114
para 6

line: var undefs = [,,]; .... comment should say "An array with 3 elements, all undefined"

Printed Page 120
first paragraph under "7.7.6 splice"

This paragraph states that splice() does not return a new array because it modifies the array in place. Actually, the both the examples below (on p. 120) and the Core JavaScript Reference entry for splice() show that splice does return a new array, as well as updating the array in place. The language used is confusing. It should indicate that the array you receive, if any, contains the removed elements, not the newly spliced array.

Printed Page 140
Example 8-3

In the function copyUndefinedProperties(), "if (!p in to)" is used to check whether the object "to" lacks property "p". Since the unary ! operator has a higher precendence than the "in" operator (see Table 5-1, pp. 60-61), this statement is incorrect: p is first negated to obtain !p, and then it is checked whether !p is a property of to. Parentheses are needed: "if (!(p in to))".

Printed Page 140
first whole function (copyUndefinedProperties)

Because the ! operator has higher precedence than the in operator, the function just checks to see if "false" is in the to object for each property in the from object. Function should be: function cu(from, to) { for(p in from) { if (!(p in to)) to[p] = from[p]; // parentheses around 'p in to' } }

Printed Page 141
code just before section 8.8

The code could be fleshed out a bit more to illustrate the idea that 'this' is a keyword never bound to any particular call object. Yes, that info is on p 137 at the end of 8.4, but by this page that info is a bit fuzzy and still abstract. Perhaps all of example 8-5 needs to be in section function makePropertiesInThis ( arg1, arg2, arg3 ) { for ( var i=0; i < arguments.length; i++ ) { this[ 'js' + i ] = arguments[i]; } return this; } o = {}; o.func = bindArguments( makePropertiesInThis, 'foo', 'bar' ); x = o.func( 'baz' ); // print is defined as earlier in the book print( x === o ); // true print( x === this ); // false print( "js0" in o ); // true, foo print( "js1" in o ); // true, bar print( "js2" in o ); // true, baz print( "js0" in this ); // false print( "js1" in this ); // false print( "js2" in this ); // false x = (bindArguments(makePropertiesInThis, 'apple'))('banana','cherry'); print( x === o ); // false print( x === this ); // true print( "js0" in this ); // true, apple print( "js1" in this ); // true, banana print( "js2" in this ); // true, cherry

Printed Page 143
first sentence

The correction at is incorrect; the sentence was correct before. The overall structure of the sentence is "The facts...interact". The sentence is describing three facts which interact. So it should be "facts" and not "fact".

Printed Page 145
Example 8-6

In Example 8-6, the "get" and "set" methods are defined, but their comments have their names confused ("getter" and "setter" should be switched). The text reads: // The setter method simply returns the value. o["get" + name] = function() { return value; }; // The getter method stores the value or throws an exception if // the predicate rejects the value. o["set" + name] = function(v) { if (predicate && !predicate(v)) {157 (4th ed.)} last paragraph (4th ed).; In Section 10.2, page 157, 4th ed., there is an example for parsing a URL using String.match(). In the last paragraph there is an off-by-one error in the description of the index property of the result: AS IS: "So, in the previous code, the value of the result.index property would be 21, since the matched URL begins at character position 21 in the text." SHOULD BE: "So, in the previous code, the value of the result.index property would be 22, since the matched URL begins at character position 22 in the text."

Printed Page 158
first paragraph

"When you use JavaScript objects to *simulate* object-oriented programming techniques ..." [emphasis added] maybe should be something like: "When you use JavaScript objects to simulate the object-oriented programming techniques of strictly-typed languages ... " On page 157: "JavaScript is a true object-oriented language." If that's true, we shouldn't need to simulate object-oriented programming techniques. If we do need to simulate them, then JavaScript must not be a true object-oriented language.

Printed Page 161
3rd paragraph (the creation of an 'instance method')

INSTANCE/CLASS METHOD CONFUSION (5th Addition Rhino Book) The definition of Circle.prototype.area = function() { etc.... } is described as an instance method, which would be a function which is present in all instances of a Circle, but could POTENTIALLY be changed without affecting other instances. eg. for these two objects - var a = new Circle(2); var b = new Circle(6); // I could do this..... b.area = function() { return 1; } I could redefine the 'area' function for 'a' but it would NOT be changed for 'b' surely? However, by defining the 'area' function as part of the prototype, that would change the function for ALL Circle instances. Therefore it is a CLASS method, not an INSTANCE method. 'area' should be defined in the constructor, just like INSTANCE PROPERTIES are. function Circle(radius) { this.r = radius; this.area = function() { return (Circle.PI * this.r * this.r); } } // and something more likely used for a class function using prototype, like: Circle.prototype.getNumberOfSides() { return 1; } (although, Circle.getNumberOfSides() is an infinitely better way!) I find the sections from 9.3.1 - 9.3.5 very confusing to read as an experienced C++ developer, as there seems to be some fuzziness in the thinking here. Also in you say the same thing, that an instance method can be defined via the prototype, but this is just plain wrong! ps. I am using the latest firefox, so I hope it's not a bug in it's interpreter! Page 161: The comment says that 9.3 is very confusing and in fact partly wrong. It isn't. Flanagan is just telling how things are done in JavaScript.

Printed Page 166
last paragraph

the "new" operator doesn't belong there. here's the output from jslint: Error: Problem at line 1 character 21: Weird construction. Delete 'new'. complexNumbers.sort(new function(a,b) { return a.compareTo(b); }); Problem at line 1 character 65: Missing '()' invoking a constructor. complexNumbers.sort(new function(a,b) { return a.compareTo(b); }); Members Occurrences compareTo 1 sort 1

Printed Page 166
last line

Remove the 'new' keyword.

Printed Page 170
sections 9.5.1 and 9.5.2

The implementation provided for simulating "super" (via the "superclass" property) does not work when more levels of class hierarchy are used than shown. For example, if Class C extends B, and Class B extends A, then when the constructor B referenced "this.superclass" (expecting a reference to "A"), it would instead get "B" because the "this.superclass" defined by C would have overridden/obscured it.

Printed Page 176
Footnote in section 9.7.3

The footnote begins: 'The term "duck typing" has been popularlized' 'popularlized' should be 'popularized'

Printed Page 203
end of page

The following statement confuses some readers (including me at first): "The non greedy version of our pattern does match at the first character of the string, so this match is returned; matches at subsequent characters are never even considered". The "does match at the first character... so this match is returned" induces people to think "the match is the first character?". I suggest the following formulation: -- The non greedy version of our pattern does match starting from the first character of the string, so the complete match is the one retained; matches starting at subsequent characters are never even considered after the first one. In other words, the match is "leftmost" ("leftmost longest" for greedy, or "leftmost shortest" for non-greedy, but always "leftmost"!). -- (I borrowed the "leftmost" concept from "Programming Perl".)

Printed Page 203
Below Table 11-3 in Chapter 11

Regarding regular expressions, the following text: /w{3}d?/ // Match exactly three word characters and an optional digit is incorrect. This regular expression will match 'AAA3' like it is supposed to. But it will also match 'AAAA3'. Since there are four A's, this regular expression does not "match exactly three word characters and an optional digit." Page 203 (regular expressions): This states that the text in the book: "/w{3}d?/ // Match exactly three word characters and an optional digit" is incorrect while it isn't. Maybe the wording isn't clear in the original comment. I'm not capable of discussing that because I'm not a native speaker of English. But the claim that the comment is wrong because of the fact that the regexp matches "AAAA3" i.e. 4 letters followed by a digit is clearly wrong. The regexp produces a match but that match does not match the whole of the string "AAAA3" it only matches the first 3 letters. This can clearly be seen with the following code that uses different letters instead of A's only: y = "ABCD3".match(/w{3}d?/); alert(y); // shows ABC y = "ABC3D".match(/w{3}d?/); alert(y); // shows ABC3

Printed Page 204
3rd paragraph, 4th sentence

It looks like there's an extra closing parentheses in "/(ab|cd)+|ef)/"

Printed Page 218
2nd bullet in section 12.1.1

The pattern in the bullets is Java -> JavaScript but the second bullet reads: * All java.lang.Number objects convert to Java numbers. I believe it should read: * All java.lang.Number objects convert to JavaScript numbers.

Printed Page 232

I cannot get the example 14-1 and 14-2 to work. I am using IE7 and checked line by line. Could there be a problem in the code?

Printed Page 275
4th paragraph, explanation of viewport (also innerwidth/innerheight p 913)

your definition of 'viewport' is (as it should be) the window minus menus, scrollbars, etc. your code works as advertised in the browsers OmniWeb and Safari on MacOS X Leopard. with the browsers Camino, Firefox, Mozilla, Navigator, SeaMonkey (all on MacOS X) and Internet Explorer 7 (on Win XP) your code returns the width of a frame including the scrollbar. Specifically on Safari, the proper width is the 'computed style width' of the body; however, this value appears to be 'auto' in the other browsers.

Printed Page 276
Also first "if" statement on page.

If not an error, this is something that should be pointed out to the reader... if(window.screenLeft) evaluates to FALSE, even with IE, if the value of screenLeft is zero. So using this code with a window that opens full-screen, for example, results in an undefined function error.

Printed Page 276
line 60 in the file js5examples/14/Geometry.js in

the book correctly says if (document.documentElement && document.documentElement.scrollWidth) { but the file contains if (document.documentElement && document.documentElemnet.scrollWidth) {

Printed Page 276
Your sole listing here is wrong It is correct the way it is printed, not with the "=== undefined" added.

Printed Page 277
line 60 of provided file 14/Geometry.js

The book is correct, but the code provided has a typo in line 60: if (document.documentElement && document.documentElemnet.scrollWidth) { the second documentElement is misspelled.

Printed Page 291
last paragraph

In the 3rd line from the bottom of page 291 there is the code line instead of All through this chapter 14 which I am currently reading, I find the expression "the Window object" ("window" with capital W and in Roman) where I would have expected to see "the window object" (that is "window" written with small w and in Constant Width).

Printed Page 323
First comment section of code

The line that says * element is looked up using getElementsById() should say * element is looked up using getElementById() There is no getElementsById() method.

Printed Page 332
fifth line of code

Example 15-9 table.appendChild(row); is not a good idea for Internet Explorer -- wants rows appended to tbody (or thead or tfoot) Firefox and Safari happy as clams I notice the screen shot (Figure 15-4) is for Firefox I admit I didn't use this script, but I can tell you that I had no luck directly appending rows to a table in MSIE. (Nothing displayed.) Cured by appending to tbody and then appending tbody to table. Found the cure by Googling.

Printed Page 335
just at the beginning of the function 'make'

See how the function begins: function make(tagname, attributes, children) { // If we were invoked with two arguments the attributes argument is // an array or string, it should really be the children arguments. The comment does not 'really' make sense (English and programming logic wise). I think that it should be rewritten as: function make(tagname, attributes, children) { // If we are invoked with two arguments and the 'attributes' argument is // an array or string, we assume that the second argument is intended // to be the 'children' arguments (ie: the real 'attributes' is missing). // This allows users not to type a null argument in this case.

Printed Page 361
first sample code for Section 16.2.3

The algorithm provided for determining element position fails in some circumstances, at least with Internet Explorer 6. With tables, there is not the expected containment hierarchy of DIV, DIV, TABLE, TBODY, TR, TD, SPAN. Instead, both TR and TD act as though TBODY were their container with respect to position; they provide the same vertical offset. TBODY may also show a vertical offset for a header row when no header is displayed. Either the recipe should be improved, or readers should be warned of its limitations.

Printed Page 380

In the discussion about Computed Styles on page 347 of the fourth edition you discuss getComputedStyle() as a property of document.defaultView. On page 380 of the fifth edition you have dropped this. Unfortunately Safari doesn't have window.getComputedStyle(). Safari does have document.defaultView.getComputedStyle(). This is the way I access the function and the Yahoo! UI library does the same.

Printed Page 382
Last paragraph

In the second sentence of the last paragraph "The HTML DOM Level 2 standard defines a disabled property for both <link> and <script> elements." the tag <script> should be the tag <style>.

Printed Page 395
3rd paragraph from bottom

The text says "The second column of Table 17-1 describes what happens when you return false." The second column of Table 17-1 actually describes what happens when the event is triggered, and the column describing what happens when the handler returns false appears to have been elided.

Printed Page 403
17.2.4 "Registering Objects as Event Handlers", second paragraph

This code block is missing a comma at the end of the third line. It should read: function(event) { listener.handleEvent(event); },

Printed Page 408

I'm not sure this is serious, but in this page *relatedTarget* is defined as returning a *Node* whereas in page 858 it's defined as returning an *Element*. in a book by another publisher, it mentions that Mozilla can return a text node as a relatedTarget, which is consistent with returning a Node instead of an Element. your book would be more *definitive* if you cleared up this inconsistency.

Printed Page 411,412,479,503

The changes made in the 08/07 printing used the literal tag syntax to designate code segments in paragraphs. These tags are present in the 01/08 printing of the book when they should have been removed before printing.

Printed Page 433
Very first line (not including the one-line header)

The comment is wrong, according to the code. Instead of // Firefox gives us printing keys in e.charCode, IE in e.charCode It should be: // Firefox gives us printing keys in e.charCode, IE in e.keyCode

Printed Page 453
Three-quarters down the code on the page

The comment of the Validate.js code claims that the anonymous function does not define any symbols in the global namespace. The code has an error that causes one of the variables to be defined in the global namespace. for (j = 0; j < f.elements[j]; // the element we're working on The above line should properly declare the j variable for (var j = 0; j < f.elements[j]; // the element we're working on

Printed Page 461
example 19-1, 4th line

current: var cookie = new Cookie("vistordata"); proposed: var cookie = new Cookie("visitordata");

Printed Page 462-463
function Cookie

document.cookie value on FireFox includes a blank space after ';'. As a result, the code to extract a particular cookie value doesn't work: var cookies = allcookies.split(';'); var cookie = null; for(var i = 0; i < cookies.length; i++) { // Does this cookie string begin with the name we want? if (cookies[i].substring(0, name.length+1) == (name + "=")) { cookie = cookies[i]; break; } } This can be easily fixed by first replacing all blanks with zero length strings, as in: var cookies = allcookies.replace(" ", "").split(';')

Printed Page 462
near bottom

As reported by a previous person the Cookie function has a problem on Firefox because of a space that is added after the semicolon to split the cookies. Thus this line: var cookies = allcookies.split(';'); Leaves a space after the split and thus doesn't work correctly when looking up cookie names. The previous errata reporter said this could be fixed like so: var cookies = allcookies.replace(' ', '').split(';'); This is not correct either because the replace needs to be global, not just for the first match: var cookies = allcookies.replace(/ /g, '').split(';');

Printed Page 464

It seems that neither IE 6 or Safari 2.0.4 support the max-age attribute for cookies. This means that the example 19.2 in your book cannot delete cookies in these mainstream browsers. This occurs in the enabled() method as well. I am reverting to the expires attribute.

Printed Page 464, 465

The anonymous functions that are defined should end with a semicolon. Currently the books shows them as = function(daysToLive, path, domain, secure) { ... } when they should be = function(daysToLive, path, domain, secure) { ... }; There are three such errors across pages 464 and 465. The first is halfway down page 464, the second is just above the comment block at the bottom of page 464, and the third is at the end of the first code section on page 465.

Printed Page 480

In the list of possible factories, could add another one: function() { return new ActiveXObject("MSXML2.XMLHTTP.3.0"); } The Yahoo! UI tests for this as the first option for IE.

Printed Page 481
At end of code sample 20-1

At the end of the code example (20-1) there is no closing semicolon. This has been copied into the http.js file supplied as part of this chapter. All other functions in this file have closing semicolons.

Printed Page 481

"By default, the open() method sets up an asynchronous XMLHttpRequest' This isn't true with all browsers. If the third argument is omitted some browsers default to synchronous. Hence the third argument has to be included all the time if the programmers wants control of whether the request is sync or async.

Printed Page 486
20.2.1 Basic Get Utilities

In HTTP.getText function, the request variable will drop out of scope once the function exits. The garbage collector might clean up the object before onreadystatechange is called

Printed Page 491

eval(request.responseText); Should be eval('(' + request.responseText + ')');

Printed Page 513
line of code in middle of page

Should the xsl definition not define an xsl file, rather than an xml file? Should it not read <xml-stylesheet href="datatoTable.xsl" "type="text/xsl"?> ??

Printed Page 517
RegExp.test Example

The example says: var pattern = /java/i; pattern.test("JavaScript"); // Returns true pattern.test("ECMAScript"); // Returns false But the second test returns false not because it doesn't contain the pattern, but because of the side effect on the lastIndex in the pattern regular expression. There should be a mention of this side effect on lastIndex in the Description section for test, and reference exec and lastIndex for more complete description. This *dangerous* side effect should be mentioned also in String.match, .search, .replace, and any other place that applies.

Printed Page 520
21.6 paragraph 2, first sentence

Example 21-12* works in IE only, not in Firefox. Book states: "This section applies the XML techniques seen earlier in the chapter and uses XPath and the DOM to create an improved templating facility that works in IE and Firefox." *12.html and xml.js run on Web server, accessed by IE and Firefox (latest Firefox version available as of January 22, 2007)

Printed Page 520
21.6 paragraph 2, first sentence

12.html and xml.js do not work in Firefox (Win XP SP20 or Firefox (Solaris 8 SPARC). This appears to be due to a namespace collision. The Firefox error console reports that Namespace "XML" already exists Substituting "dXML" for "XML" (in both files) fixed the problem.

Printed Page 526
4th row from bottom

the object XML is not declared

Printed Page 537
example 22.4

The ImageLoop constructor function sets the image load event for each image before the event function is ready. The result is that the event handler can fail if the images have been cached. What really matters is the "var loop = this;" line. If the browser loads the image in a separate thread the event handler can fire and call countLoadedFrames() before that line is executed. I see this most often with IE7. The fix is to move the event handler code before the loop that processes the image URLs: // This nested function is an event handler that counts how many // frames have finished loading. When all are loaded, it sets a flag, // and starts the animation if it has been requested to do so. var loop = this; function countLoadedFrames( ) { loop.loadedFrames++; if (loop.loadedFrames == loop.frames.length) { loop.loaded = true; if (loop.startOnLoad) loop.start( ); } } // Initialize the frames[] array and preload the images for(var i = 0; i < frameURLs.length; i++) { this.frames[i] = new Image( ); // Create Image object // Register an event handler so we know when the frame is loaded this.frames[i].onload = countLoadedFrames; // defined above this.frames[i].src = frameURLs[i]; // Preload the frame's image }

Printed Page 551
End of Example 22-8

missing final closing '}' at the end of the example

Printed Page 609
deleteCount description for Array.splice()

While it would be nice if it was, the deleteCount argument to Array.splice() is not optional according to the ECMAScript v3 spec [1], and according to the spec, a value of undefined should behave the same as the number zero. When this argument is omitted, you get inconsistent behaviour across browser implementations. The example given on page 610 states var a=[1,2,3,4,5,6,7,8]; a.splice(4); // Returns [5,6,7,8]; a is [1,2,3,4] But the actual results are: Firefox 2 + 3: Returns [2,3,4,5,6,7,8]; a is [1] IE 6 + 7: Returns []; a is [1,2,3,4,5,6,7,8] Opera 9.27: Returns []; a is [1,2,3,4,5,6,7,8] Opera 9.5: Returns []; a is [2,3,4,5,6,7,8] Safari 3.1.1: Returns [2,3,4,5,6,7,8]; as is [1]

Printed Page 667
"Returns" section of Math.random()

The book says that Math.random() returns "A pseudorandom number between 0.0 and 1.0." Section of ECMA-262 says it "Returns a number value with positive sign, greater than or equal to 0 but less than 1". That "less than 1" can be of significance, since Math.floor(Math.random() * N) where N is an integer might return N itself; otherwise, we can safely assume that expression will return an integer from 0 to N-1.

Printed Page 708
in Bugs section for String.substr()

The Bugs section for String.substr() states in part, "Negative values for start do not work in IE 4 (this is fixed in later versions of IE)." However, I do not think that this problem has ever been fixed in IE. I just tried it in IE 7 and it's still broken.

Printed Page 833
The Image object title block

The Inherits from section should presumably end with Image rather than Input But is the inheritance chain correct otherwise??

Printed Page 834
Section entitled "HTML Syntax"

The Image object is described as having onload, onerror, and onabort event handler attributes. Those attributes are not valid (X)HTML for the IMG tag, and the DOM does not indicate that the HTMLImageElement has those properties (e.g. the load event only applies to the body, FRAMESET, and OBJECT elements--see DOM2-Events section 1.6.5). However, it appears most browsers support these attributes.

Printed Page 841
Paragraph on method.

The book states: The click() method is not often useful. Because it does not invoke the onclick event handler, it is not useful to call this method on elements of type "button"; ... -------------- This is a mistake. Try this code. It executes click() method and it fires the onclick() event on button. It works on IE and mozilla firefox: <form action="DEFANGED_javascript:void 0;"> <input type="button" id="mybutton" DEFANGED_Onclick="alert('I was clicked');" value="my button"> </form> <DEFANGED_script> document.getElementById("mybutton").click(); </script>

Printed Page 858
4th paragraph from the bottom

The information about the related target properties refers to elements, whereas the last paragraph of page 408 refers to nodes. Both paragraphs are not consistent with each other. As text nodes can be the related target and text nodes are not elements, the paragraph on page 858 should be updated. If it is decided that text nodes should not allowed as a related target, the last paragraph on page 408 should be updated.

Printed Page 876

space is missing around HTMLFormElement

Printed Page 896

The second argument of the add() method is an index (integer) in IE: try { select.add(theOpt, anOpt); } // standards compliant catch(ex) { select.add(theOpt, indexOfAnOpt); } // IE only

Printed Page 913
innerHeight and innerWidth

innerHeight and innerWidth, under Firefox, are the client area size, including the scrollbars. To have the viewport size, you must use document.documentElement.clientWidth and document.documentElement.clientHeight. Tested on Firefox 2.0.

Printed Page 933
on this page The following errata is incorrect: Title line for XMLHttpRequest; Internet Explorer 5.0 should be Internet Explorer 7.0 It is actually appropriate to list IE 5 instead of IE 7, because the section below clearly states that IE5 and IE6 support the underlying functionality, simply with a different call.

Printed Page 943
5 lines from bottom of page

snapshotLength should be readonly long snapshotLength

Printed Page 943
2 lines from bottom of page

stringValue should be readonly String stringValue