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. If the error was corrected in a later version or reprint the date of the correction will be displayed in the column titled "Date Corrected".

The following errata were submitted by our customers and approved as valid errors by the author or editor.

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



Version Location Description Submitted By Date Submitted Date Corrected
Printed
Page XV
Chapter "Errata and how ..."

The web site for errata http:/oreilly.com/catalog/9780596805531 should read http://oreilly.com/catalog/errata.csp?isbn=9780596805531

Lutz Adam  Jan 21, 2012 
Printed
Page various
various

In my eyes the message of section 6.2.3 is, that if(book.subtitle) should make sure the existence of this property. But according to section 15.5.2 such a simple "if(...)" does not take care of an empty string. In both situations I don' t understand, why the in-operator (see section 4.9.3) must stay unused for those questions.

Note from the Author or Editor:
Change code sample to: // A verbose and explicit technique var len = undefined; if (book) { if ("subtitle" in book) len = book.subtitle.length; } // A concise and idiomatic alternative to get subtitle length or undefined var len = book && ("subtitle" in book) && book.subtitle.length;

Anonymous  Sep 02, 2013 
Printed
Page page 405
code

var args = document.referrer.substring( ref.indexOf("?") + 1). split("&"); Flanagan, David (2011-04-18). JavaScript: The Definitive Guide (Definitive Guides) (p. 405). O'Reilly Media. Kindle Edition. correct version:var args = document.referrer.substring( referrer.indexOf("?") + 1). split("&");

Note from the Author or Editor:
Change line to: var args = document.referrer.substring(document.referrer.indexOf("?")+1).split("&");

Maria Grynychyn  Dec 29, 2013 
Safari Books Online
1
Table of Contents

In the Safari Online PDF (which is no longer labeled as a Rough Cut), in the PDF table of contents for Parts III and IV, the different entries don't actually take you to their associated pages. This DRASTICALLY reduces the usefulness of this PDF as a reference.

Note from the Author or Editor:
Resolution: Is this still a problem? Sounds like something to fix. I don't know what a Safari PDF is unless it is the same as the normal PDF, but available through safari to those who bought the rough cut...

Beau  Apr 30, 2011 
Printed
Page 4
3rd comment in 1.1

“variable” could be written with a capital v

Note from the Author or Editor:
Change "variable is a symbolic name for a value." to "A variable is a symbolic name for a value."

Angelos Sphyris  Aug 05, 2013 
Printed
Page 5
2nd paragraph of text

“The use of . and [] … for example” could be better written: “For example, the use of . and [] to refer to the value of an object property or array element yields an expression.”

Note from the Author or Editor:
Rephrase as per description of error.

Angelos Sphyris  Aug 05, 2013 
Printed
Page 6
4th line of comments

the comma before “too” should be omitted

Note from the Author or Editor:
Change wording to avoid the comma altogether: points[1].x - points[0].x // => 1: more complicated operands work, too becomes points[1].x - points[0].x // => 1: more complicated operands also work

Angelos Sphyris  Aug 05, 2013 
PDF
Page 9
Last paragraph

The sentence in the last paragraph that reads: A function is a named and parametrized block... should read: A function is a named and parameterized block...

Note from the Author or Editor:
I suspect that the spelling of parametrized is a house style issue. I don't care either way. Please check and leave it as is if the e was dropped intentionally.

Javier Estrada  Jul 19, 2011  Aug 12, 2011
Printed
Page 11
code example for the "load" event

I couldn’t get function hide to work. Instead, I used: function hide(event) { var target = event.target ? event.target : event.srcElement; //srcElement needed for IE8, target for Chrome and FireFox target.style.visibility = "hidden"; }

Note from the Author or Editor:
Changed code for function to: function hide(event) { // srcElement needed for IE8, target for Chrome and Firefox var target = event.target ? event.target : event.srcElement; target.style.visibility = "hidden"; }

Angelos Sphyris  Aug 05, 2013 
Printed
Page 13
Example 1.1

The <tr> lines for Repayment period and Zipcode do not have matching </tr> codes. Although the code seems to work fine without them, I've always been told that it's "good programming practice" to include them. (I've also downloaded the code from the website, and found it also has the same problem.)

Note from the Author or Editor:
Added </tr> tags at end of the lines:

Clark Jones  Jul 06, 2013 
Printed
Page 19
First sentence

"This part of the book, Chapters 2 though 12,...." should read "This part of the book, Chapters 2 through 12,..."

Note from the Author or Editor:
Make change as specified: "This part of the book, Chapters 2 through 12,..."

Mikael Strand  May 21, 2013 
Printed
Page 35
last line

“hours in UTC time; depends on timezone” Is this really so? I thought UTC time was absolute and it was the local time, which was dependent on the timezone.

Note from the Author or Editor:
Changed line to: later.getUTCHours() // hours in UTC time

Angelos Sphyris  Oct 01, 2013 
Other Digital Version
36
Second set of examples in String Literals section

The comment describing the one-line string written on 3 lines is nested within the string literal. This makes the comment part of the string literal and the backslash is not part of a line continuation.

Note from the Author or Editor:
Move comment to precede the strings: // A string representing 2 lines written on one line "two\nlines" // A one-line string written on 3 lines. ECMAScript 5 only. "one\ long\ line"

Evan Thomas  Sep 09, 2011 
Printed
Page 40
section 3.3, 7th paragraph

The first occurrence of the word 'truthy' is written in the font used for programme code. Perhaps this is a formatting error.

Note from the Author or Editor:
Set "truthy" in italic.

Angelos Sphyris  Oct 01, 2013 
PDF
Page 41
Last paragraph

The last paragraph starts with the following sentence: "+, ==, != and the relational operators are the only ones that perform this special kind of string-to-primitive conversions" I believe that instead of "string-to-primitive conversions" it should've been "object-to-primitive conversions". Two reasons: 1) The specific conversion the author is probably referring to is described above using the "object-to-primitive" term 2) String is already a primitive, so the "string-to-primitive conversion" term makes no sense.

Note from the Author or Editor:
Change text to read "...perform this special kind of object-to-primitive conversions"

Anonymous  Jun 12, 2013 
PDF
Page 43
4th paragraph under section 3.6 Wrapper Objects

The text 'There are not wrapper objects for the null and undefined values' should be changed to 'There are no wrapper objects for the null and undefined values'

Shuaib Mohammad  Sep 28, 2012 
PDF
Page 43
4th paragraph (after the 1st sample code)

The following phrase is confusing: "Strings are not objects, though, so why do they have properties?". This affirmation is not true for every case. For example, in the following code, myString is an object: var myString = new String("this is my string"); I think that the text could be modified to: "Primitive strings are not objects, though, so why do they have properties?". Then, the author must explain the difference between primitive strings, and string objects. The String documentation on String global object has a topic, called "Distinction between string primitives and String objects" that is superb. The following sample code is enlightening: var s_prim = "foo"; var s_obj = new String(s_prim); console.log(typeof s_prim); // Logs "string" console.log(typeof s_obj); // Logs "object"

Note from the Author or Editor:
Change "Strings are not objects" to "Primitive strings are not objects"

Rogério Moraes de Carvalho  Dec 24, 2012 
Printed
Page 46
Table 3-2, lower left cell, middle

I have convinced myself that the text "[9] (1 nuemeric elt)" is using "elt" as an abbreviation for "element". However, I had to stop and think about this. It is generally better to introduce abbreviations when first using them.

Note from the Author or Editor:
If it is possible to so without word wrap, change "(1 numeric elt)" to "(one numeric element)"

Anonymous  Sep 17, 2011 
PDF
Page 58
JavaScript source code after the 3rd text paragraph

The comment of the first line reserved word primary expression has the word "Evalutes" instead of "Evaluates".

Rogerio Moraes de Carvalho  Dec 25, 2012 
Printed
Page 59
Last line on page.

The code example: var square = function(x) { return x * x; } should include a final semi-colon at the end of the line to reflect best practices as well as to continue the correlation between object and array literals that precede it (where this syntax is used properly): var square = function(x) { return x * x; };

Note from the Author or Editor:
Include a final semi-colon at the end of the line: var square = function(x) { return x * x; }; (The same example on page 7, though split across several lines, has a semicolon after the closing brace.)

Scott Marcus  Nov 29, 2011 
Printed
Page 59
3rd paragraph

“A single trailing comma is allowed…undefined element.” I can understand what is meant here, yet the sentence can prove somewhat confusing, because if we define: var a = [1,,3,] then a[3] is undefined. In fact, a[i] for all i >= 3 is undefined. I would emphasise the phrase “not create” and add a further sentence, such as: “However any array access expression for an index after that of the last expression will necessarily evaluate to undefined”.

Note from the Author or Editor:
Add wording: "However, any array access expression for an index after that of the last expression will necessarily evaluate to undefined." Did not emphasise the phrase "not create"

Angelos Sphyris  Oct 01, 2013 
PDF
Page 60
3rd paragraph

This second expression specifies the name of the desired property OF the index of the desired array element. should read This second expression specifies the name of the desired property OR the index of the desired array element.

Note from the Author or Editor:
fix, please

leppie  Apr 27, 2011  Aug 12, 2011
PDF
Page 60
4th paragraph

I initially misinterpreted the sentence "If the value is not an object (or array), it is converted to one (see §3.6)." I thought that the value would be converted to either an object OR AN ARRAY (depending on context somehow) but this is not the case; it is always converted to an object. I suggest changing the end of this sentence to "..., it is converted to an object". This phrasing would have prevented my confusion.

Note from the Author or Editor:
Make change as per description of error.

TadMarshall  Sep 18, 2011 
PDF
Page 60
5th paragraph

In the first sentence in this paragraph, "when you know then name" should be "when you know the name".

Note from the Author or Editor:
Make change as in description of error.

TadMarshall  Sep 18, 2011 
Printed
Page 60
5th paragraph

For "know then name" read "know the name".

Martin Leese  Dec 30, 2012 
PDF
Page 60
2nd paragraph of the topic 4.4 Property Access Expressions

Note the asterisks in the following paragraph detached phrase: "This second expression specifies the name of the desired property *of* the index of the desired array element." The correct must be "or" instead of "of".

Note from the Author or Editor:
Already fixed in current version of PDF.

Rogerio Moraes de Carvalho  Dec 25, 2012 
Printed
Page 60
5th paragraph

“If the property name is a reserved word … you must use the square bracket notation.” However, the following works: var p = { "goto" : 1, "void" : 2 }; p.goto + p.void //=> 3

Note from the Author or Editor:
Commenter's example works correctly in both Firefox and Chrome, latest versions. Action: Comment out <!--is a reserved word or-->

Angelos Sphyris  Oct 01, 2013 
Printed, PDF
Page 62
Table 4-1 JavaScript operators

This is really a question about an omission from Table 4-1. In the table of JavaScript operators, Table 4-1 starting on page 62, the expressions '[ ]', '( )' and '.' are omitted from the start of the table. Although these are really expressions rather than operators, most experienced programmers from other languages (e.g. C and Java) would want them to be there, for convenience. It is useful to think of them as operators when reading code. The book isn't a strict reference like the ECMAScript standard, it's a book for learning the language. FWIW, Crockford includes them in his 'operator precedence' table in JavaScript: The Good Parts (which I ended up referring to in order to find out about these expressions/operators). Please add them to the table!

Note from the Author or Editor:
Split this off into a new table at the end of the preceding section, with this text preceding the table: <para><xref linkend="exprPriority" /> gives the precedence for these expressions. They are all of higher priority than the operators shown in <xref linkend="operators" />. The expressions listed first have higher precedence than those listed last. Expressions separated by a horizontal line have different precedence levels. The column labeled A gives the expression associativity, which can be L (left-to-right) or R (right-to-left).</para>

ar42  May 10, 2012 
PDF
Page 75
Fourth line before 4.10 title

"If it finds it, then o is an instance of f (or of a superclass of f) and the operator returns true." Shouldn't it be "a subclass of f"? Otherwise the Liskov Subtitution Principle would not be valid for JavaScript.

Note from the Author or Editor:
Correct. If I ask whether a Date is an instanceof Object, the answer is yes, because Date is a subclass of Object. Action: change "a superclass of" to "a subclass of"

Sergio Arbeo  Sep 17, 2011 
PDF
Page 75
examples near top of page

Lines 2, 3, 4, 6, 7 and 8 should not have semicolons, to match the style of other examples in the book. In other examples, statements end in semicolons while expressions such as '1 + 2' or (here) 'd instanceof Date'' do not.

Note from the Author or Editor:
Remove semicolons from lines containing expressions: var d = new Date(); // Create a new object with the Date() constructor d instanceof Date // Evaluates to true; d was created with Date() d instanceof Object // Evaluates to true; all objects are instances of Object d instanceof Number // Evaluates to false; d is not a Number object var a = [1, 2, 3]; // Create an array with array literal syntax a instanceof Array // Evaluates to true; a is an array a instanceof Object // Evaluates to true; all arrays are objects a instanceof RegExp // Evaluates to false; arrays are not regular expressions

TadMarshall  Sep 18, 2011 
Safari Books Online
75
3rd paragraph

Section 4.9.4: The InstanceOf Operator Last sentence of 2nd text paragraph (ignoring code sample) reads: If the right-hand side is not a function, it throws a TypeError. I believe "function" should be "object" or "Class of Objects".

Note from the Author or Editor:
Reword to "If the right-hand side is not a class of objects,..."

Greg Edwards  Mar 22, 2013 
PDF
Page 77
3d paragraph, second code example

function copy(o, p) { p = p || {}; // If no object passed for p, use a newly created object. // function body goes here } I believe properties of O should be assigned to P. function copy(o, p) { p = o || {}; // If no object passed for p, use a newly created object. // function body goes here }

Note from the Author or Editor:
Make change as specified in description of error.

Víctor  Dec 11, 2013 
PDF, Other Digital Version
Page 80
First paragraph, Last sentence

If this isn't a typo, the intended meaning isn't clear. If the string throws an exception, the eval() propagates that expression. should be If the string throws an exception, the eval() propagates that exception.

Note from the Author or Editor:
Change it to: If the evaluated string throws an exception, that exception propagates from the call to eval().

Andrew Hart  Jun 11, 2011  Aug 12, 2011
Safari Books Online
84
1st example at "4.13.3 The delete Operator"

The delete operator example for array at 4.13.3 is described below, however, I've found that a.length is still 3 even after "delete a[2]" on my FireFox5 and Chorme14. 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 The specification of delete operator on FireFox at https://developer.mozilla.org/en/JavaScript/Reference/Operators/Special_Operators/delete_Operator says that "When you delete an array element, the array length is not affected." so this example is wrong.

Note from the Author or Editor:
Change this line: a.length // => 2: array only has two elements now To these two lines: 2 in a // => false: array element 2 doesn't exist anymore a.length // => 3: note that array length doesn't change, though Line the comments up with the ones above, of course. Also, if you can make it fit somehow, add the following at the end of the paragraph that follows after "with the in operator (§4.9.3).": Deleting an array element leaves a "hole" in the array and does not change the array's length. The resulting array is <emphasis>sparse</emphasis> (see §7.3).

Shigeki Ohtsu  Jun 29, 2011  Aug 12, 2011
PDF
Page 84
last line in the first example group

a.lenth should be a.length Apparently fallout from fixing the confirmed erratum on this line (reported by Shigeki Ohtsu), since the typo does not appear in that report.

Note from the Author or Editor:
change a.lenth to a.length

TadMarshall  Sep 19, 2011 
Printed
Page 92
Section 5.3.2: 1st line on page 92

Like variables declared with var, functions defined with function definition statements are implicitly "hosted" ... should read: Like variables declared with var, functions defined with function declaration statements are implicitly "hosted" ...

Note from the Author or Editor:
Change text to: "...functions defined with function declaration statements are implicitly “hoisted” to the top of the containing script or function"

April  Sep 06, 2011 
PDF
Page 95
repeated if/else -> switch statement example

The comments for the switch statement cases are using the wrong equality operator. In the book: "Start here if n == x" Correct: "Start here if n === x" Explanation: The switch statement uses the strict equality operator to determine which case to branch to as you mention yourself just a few lines above the example. The comments should therefore use the correct equality operator.

Note from the Author or Editor:
Change "==" to "===" in three comments on page 95.

Ole Rasmussen  May 20, 2011  Aug 12, 2011
PDF
Page 95
third paragraph

The section on switch statements includes this statement: "Various locations in the block of code are labeled with the case keyword followed by an expression and a colon. case is like a labeled statement". But labeled statements haven't been covered yet (they are covered later in the chapter), so it is odd to use it in as an analogy.

Note from the Author or Editor:
Confirmed. Added a link to the appropriate section: ...is like a labeled statement (see <xref linkend="labeledstatements" />), except that instead of giving the labeled statement a name

Anonymous  Jan 09, 2012 
Safari Books Online
119
code example in 6.2.1

The example is missing the right curly bracket in the for-loop as below. var addr = ""; for(i=0; i < 4; i++){ add += cusotmer["address" + i] + '\n';

Note from the Author or Editor:
Remove the unbalanced "{" after "i++)". Note that this code is on page 121 in my pdf.

Shigeki Ohtsu  Jul 12, 2011  Aug 12, 2011
PDF
Page 127
function merge....

function merge(o, p) { ..... if (o.hasOwnProperty[prop]) continue; .... } Shouldn't the square brackets be round brackets instead? ie. if (o.hasOwnProperty(prop)) continue;

Note from the Author or Editor:
Change square brackets to round brackets as in description of error.

Jeremy Peck  Aug 17, 2011 
Printed
Page 127
in code for function merge()

The code in function merge() should have parentheses surrounding prop rather than square brackets in the line: if (o.hasOwnProperty(prop)) continue; NOT if (o.hasOwnProperty[prop]) continue; Also, in all of the examples on page 127, it would be better to include a var expression inside the for/in loop. That is: for (var prop in p) instead of for (prop in p)

Note from the Author or Editor:
Square brackets -> parentheses is a duplicate; change for (prop in p) to for (var prop in p) in all examples on page 127; also change for (p in o) to for (var p in o) in examples on pages 126 and 127.

Jeff Tash  Nov 12, 2012 
Printed
Page 128
2nd function

The function "union"'s comment section notes that "If o and p have properties by the same name, the values from o are used". It should read "the values from p are used".

Note from the Author or Editor:
change the comment as the reader suggests

Dave Gibson  Jun 02, 2011  Aug 12, 2011
Safari Books Online
128
code example in 6.6

The code example below is for obtaining a polar coordinate of (0,0) with the inherited object. The radius and theta at the coordinate origin point are not intuitive so that it's better to change the point into (0,1) or whatever not (0,0) var q = inherit(p); q.x = 0, q.y = 0; console.log(q.r); console.log(q.theta);

Note from the Author or Editor:
Change this line: q.x = 0, q.y = 0; // Create q's own data properties To this: q.x = 1; q.y = 1; // Create q's own data properties Note the numbers change and the comma changes to a semicolon. Note also that this is on page 130 of my pdf.

Shigeki Ohtsu  Jul 12, 2011  Aug 12, 2011
Printed
Page 135
code at bottom

Object.prototype.isPrototypeOf(o) // => true: p inherits from Object.prototype Should read, Object.prototype.isPrototypeOf(o) // => true: o inherits from Object.prototype

Note from the Author or Editor:
The reader is correct that there is a problem, but the proposed solution is wrong. Change the line: Object.prototype.isPrototypeOf(o) // =>; true: p inherits from Object.prototype To: Object.prototype.isPrototypeOf(p) // =>; true: p inherits from Object.prototype

Evan Carroll  Jun 20, 2011  Aug 12, 2011
Printed
Page 143
3

The second sentence of this paragraph reads: "All indexes are property names, but only property names that are integers between 0 and 2^32 - 1 are indexes." This is misleading. According to the ECMAScript spec (section 15.4, both the 3rd and 5th edition): "A property name P (in the form of a String value) is an array index if and only if ToString(ToUint32(P)) is equal to P and ToUint32(P) is not equal to 2^32 - 1." So the second sentence of your paragraph should read: "All indexes are property names, but only property names that are integers between 0 and 2^32 - 2 are indexes." Thanks so much for writing this book!

Note from the Author or Editor:
Good catch! Change 2<superscript>32</superscript>-1 to 2<superscript>32</superscript>-2

Anonymous  May 08, 2011  Aug 12, 2011
PDF
Page 144
5th paragraph ("Note that when you omit...")

quote from Ch. 7.3 p. 144 >>> "Note that when you omit value in an array literal, you are not creating a sparse array. The omitted element exists in the array and has the value undefined. This is subtly different than array elements that do not exist at all. You can detect the difference between these two cases with the in operator: 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" <<< end of quote However, v8 implementation of this differs from what the book suggests; both "0 in a1" and "0 in a2" are false. Also, the developers say v8 follows the ECMAScript specification. If that is true, the quoted text is erroneous. The issue is discussed in the following v8 bug which also contains a quote from the ECMAScript specification: http://code.google.com/p/v8/issues/detail?id=1371

Note from the Author or Editor:
Resolution: Yuck! The 4th paragraph of page 144 plus the 4 lines of code after it plus the one line paragraph after the code all have to be removed and replaced with the following: Note that when you omit a value in an array literal (using repeated commas as in <literal>[1,,3]</literal>) the resulting array is sparse and the omitted elements simply do not exist: var a1 = [,]; // This array has no elements and length 1 var a2 = [undefined]; // This array has one undefined element 0 in a1 // => false: a1 has no element with index 0 0 in a2 // => true: a2 has the undefined value at index 0 Some older implementations (such as Firefox 3) incorrectly insert the <literal>undefined</literal> values in array literals with omitted values. In these implementations <literal>[1,,3]</literal> is the same as <literal>[1,undefined,3]</literal>. Also, on page 142, the 3rd paragraph and the two lines that follow and the paragraph after that must be changed as follows: If an array literal contains multiple commas in a row, with no value between, the array is sparse (see 7.3). Array elements for which values are omitted do not exist, but appear to be <literal>undefined</literal> if you query them: var count = [1,,3]; // Elements at indexes 0 and 2. count[1] => undefined var undefs = [,,]; // An array with no elements but a length of 2 Array literal syntax allows an optional trailing comma, so <literal>[,,]</literal> has a length of 2, not 3. Hopefully these two changes sort of balance each other out and do not cause too many page break changes. Let me know if you need to shorten or lengthen them.

Marja Hölttä  May 09, 2011  Aug 12, 2011
Printed, PDF
Page 159
2nd line from the bottom

"it does not property expand that object into the returned array." should read: "it does not properly expand that object into the returned array."

Note from the Author or Editor:
Make change as per description of error.

Mingway Huang  Aug 31, 2011 
Printed
Page 160
bottom of page

var s = test should be var s = "test"

Note from the Author or Editor:
Put in the quote marks.

Anonymous  Jun 29, 2014 
PDF
Page 165
last sentence

Variable declarations are hoisted (see §3.10.1, but assignments... shoudld be: Variable declarations are hoisted (see §3.10.1), but assignments...

Note from the Author or Editor:
Yes, add the missing close paren

Anonymous  Jul 26, 2011  Aug 12, 2011
Safari Books Online
169
Section 8.2.2, second paragraph after the "Method Chaining" boxed note

David, In the sentence "Unlike variables, the this keyword does not have a scope, and nested functions to not inherit the this value of their caller.", I think you meant to say that nested functions do not inherit the this value of their "outer function". As you mention later in the paragraph, one might mistakenly assume that the inner function body has the this value in effect where it is defined (in the manner of a closure), but nobody would suspect that an inner function gets the *caller's* this. I'm seeing this in the rough cuts April 16th PDF version. Great book! Best Regards, Tom

Note from the Author or Editor:
Change "do not inherit the this value of their caller" to "do not inherit the <literal>this</literal> value of the containing function".

Anonymous  Apr 29, 2011  Aug 12, 2011
Printed
Page 180
Bottom of Example 8-3

In Example 8-3, the nested patched_extend(o) function references the protoprops variable defined in its surrounding function, but the assignment of an array of strings to the protoprops variable is unreachable code. The declaration of the protoprops variable will be hoisted, but since the unnamed outer function will always return either the extend(o) or the patched_extend(o) function before the assignment statement itself is executed, the value of protoprops should always be undefined.

Note from the Author or Editor:
This is another good catch. Move the 4 lines beginning with the blank line before this one: // This is the list of... Up so that they appear right after this line: // properties of Object.prototype. You should end up with a 4-line comment block, followed by a blank line, followed by a one line comment, followed by 2 lines beginning "var protoprops = " followed by the line "return function patched_extend(0) {" and all the code that follows that. The example should still end with the line "}());"

Matthew Engel  Jul 27, 2011  Aug 12, 2011
PDF
Page 191
2nd paragraph at 8.7.7 Callable Objects

in the book: "getElementsById()" should be: "getElementById()"

Note from the Author or Editor:
Make change as in description of error.

Hiroki Ogasawara  Sep 20, 2011 
PDF
Page 203
last line

c === F // => true: F.prototype.constructor==F for any function Should that comment be so? c === F // => true: F.prototype.constructor===F for any function

Note from the Author or Editor:
Sure. Change == in the comment to ===. And if it will fit, add spaces on both sides of ===. I probably used == to save space, but it looks like we can fit more characters on the line.

Anonymous  Aug 02, 2011  Aug 12, 2011
Printed
Page 208
Section 9.4: First paragraph

<pre> Page 208: Section 9.4: First paragraph: ... an object inherits properties from its prototype, even if the prototype changes after the object is created. is at least misleading. 'prototype' is the name of a pointer/reference to a object which contains the prototypical properties since arrays/objects are referenced by pointer/reference (section 3.7). This is a perfect example of pointer/reference access to one object using different copies of the same pointer/reference. I think saying 'even if the prototype's properties, but not the actual prototype, changes, since the prototype is referenced by pointer/reference ...' would be clearer and let one see just why changes in the prototype do affect old objects. SAMPLE: ======= I will look at an object which is an instance of a class for which the prototype is created as a property of the constructor. I will use 'print' for output (the spider monkey stand alone interpreter's output function). If you change the prototype itself, the POINTER to the object of prototypical values, then new objects use the new prototype but *OLD OBJECTS USE THE OLD PROTOTYPE*. The new objects (objects created after the prototype changes) contain pointers to the new object containing the new prototype values while the old objects use the old prototype (pointer/reference to the old prototype's object). function Test1() {};Test1.prototype={a:1,b:2} T=new Test1 print(T.a);print(T.b);print(T.c) Test1.prototype={a:10,b:20,c:30} U=new Test1 print(T.a);print(T.b);print(T.c) print(U.a);print(U.b);print(U.c) gives 1, 2, undefined [original T before the prototype has changed] 1,2, undefined [original T AFTER the prototype has changed] <-- 10,20,30 [U - created AFTER the prototype has changed] T retains the old prototype, i.e. the pointer to the old prototype's object. On the other hand, if you change the CONTENTS of the prototype object but not the prototype (i.e. the pointer/object containing the values): function Test2() {};Test2.prototype={a:1,b:2} V=new Test2 print(V.a);print(V.b);print(V.c) Test2.prototype.a=10;Test2.prototype.b=20;Test2.prototype.c=30 W=new Test2 print(V.a);print(V.b);print(V.c) print(W.a);print(W.b);print(W.c) Then one gets: 1, 2, undefined [original V before the prototype has changed] 10,20,30 [original V AFTER the prototype has changed] <-- 10,20,30 [W - created AFTER the prototype has changed] If an instance of an class contained a reference to its constructor (instead of the constructor's prototype) and actually used that to access the prototype object of its class/constructor (rather than having a pointer to the prototype object used when it was constructed itself) then one could change the prototype object (not just its contents) (as a property of the constructor) and the changed prototype would affect both new *and old* instances: function Test3() {this.constructor=Test3}; Test3.prototype={a:1,b:2} X=new Test3 print(X.constructor.prototype.a);print(X.constructor.prototype.b);print(X.constructor.prototype.c) Test3.prototype={a:10,b:20,c:30} Y=new Test3 print(X.constructor.prototype.a);print(X.constructor.prototype.b);print(X.constructor.prototype.c) print(Y.constructor.prototype.a);print(Y.constructor.prototype.b);print(Y.constructor.prototype.c) produces: 1, 2, undefined [original X before the prototype has changed] 10,20,30 [original X AFTER the prototype has changed] 10,20,30 [Y - created AFTER the prototype has changed] Now I wonder what intricacies are created when a constructor which is an internal function to another is called - if the constructor's 'prototype' is set equal (f.prototype=p) to an internal variable of the containing function ... or various properties of the prototypical object are set equal to internal variables .... </pre>

Note from the Author or Editor:
Okay, change "even if the prototype changes" to "even if the properties of the prototype change"

Anonymous  Jul 05, 2011  Aug 12, 2011
Printed
Page 309
Example 13.1

Hello! In example 13.1, the JavaScript program loops through elements of the class "reveal". In this example, there is only ONE such element, though. I assume that the aim is that this program should work fine even if the dom contains several elements of this class, otherwise, you would not need to loop through them all. But, if you add elements of the class "reveal", it will not work: No matter on which of these elements you click, only the last one will be toggled. This problem is exactly what Douglas Crockford explains on page 39 in "The good parts". Regards! Saašha,

Note from the Author or Editor:
This is an embarassing bug, that is explained on page 185 of the book. Please change JavaScript code in the example to the code shown here: https://github.com/davidflanagan/javascript6_examples/blob/master/examples/13.01.reveal.html

SaaÅ¡ha Metsärantala  Dec 31, 2011 
Printed
Page 351
14.7 first paragraph

"... and whose name is the HTMLElement ..." should read: and whose value is the HTMLElement

Note from the Author or Editor:
yes, make that change.

jonsen  May 27, 2011  Aug 12, 2011
Printed
Page 369
Section 15.2.5, 3rd paragraph

'Any <span> with "warning" and "fatal" in its class' shoud read 'Any <span> with "fatal" and "error" in its class'

Ken Wilson  Aug 01, 2011  Aug 12, 2011
Printed
Page 398
8th entry in table

For "<input> element it type attribute" read "<input> element if type attribute".

Martin Leese  Dec 30, 2012 
PDF
Page 416
16.1.4, 2nd sentence, 1st paragraph

Firefox CSS extensions are prefixed with "-moz-" Therefore, the beginning: Firefox uses moz-, ... has to be corrected as: Firefox uses -moz-, ... https://developer.mozilla.org/en-US/docs/CSS/CSS_Reference/Mozilla_Extensions

iwanaga  Oct 29, 2012 
Printed
Page 471
4th paragraph, opening sentence

Text says "In Firefox you can the nonstandard ...". Should it read "In Firefox you use the nonstandard ..."?

Ken Wilson  Aug 03, 2011 
Printed
Page 499
Example 18-2

Comment is "If the request was compete and successful". Should read "If the request was complete and successful".

Ken Wilson  Aug 03, 2011 
Safari Books Online
501
Example 18-3

Comment "If the request was compete and successful" should be "If the request was complete and successful".

Scott Murray
Scott Murray
O'Reilly AuthorO'Reilly Blogger 
Jan 22, 2013 
Printed
Page 502
Example 18-4

Page 503; Example 18-5, first paragraph following: "HTML forms generate POST requests by default." Is that true? Perhaps XMLHTTPRequest does, but do HTML forms default to POST? Page 502 and 503: Example 18-4: encodeFormData() function. I believe there are other locations where this procedure is used (decoding data, etc.). The code indicates that to *encode* data, first replace spaces with "+" then encodeURIComponent. To *decode* submitted data, first decodeURIComponent and then replace "+" with space (I am *sure* I saw that decoding somewhere, using 'unescape' - but it seems to be wrong). Done that way, spaces and "+"s in the original text are mixed and cannot be unmixed. encodeURIComponent appears *not* to act precisely the way a form submission acts in encoding items. In submission of a real form on an HTML page, submitted data first has "+"s encoded (HEXed/escaped) but SPACES ARE LEFT ALONE (not escaped). After that step (escaping) spaces are converted to "+" as the final encoding step. Apparently this is a hold over from old formats when only plain text (no "+"s!) with spaces was expected (if that is the case, then just convert spaces to + to send it without problems and there is no mixing of "+" and space as the original text had no "+"s). That is the data (first escape some characters, including "+" but EXCLUDING spaces, and then change spaces to "+"). I guess, if done now, both "+" and spaces would simply be escaped. On the other hand, encodeURIComponent seems to escape both spaces AND "+" - a bit different from www-form encoding (in which case don't do any of the space/+ conversions in creating data, there won't be any problem or spaces or "+" after endodeURIComponent). Hopefully servers will handle decoding of submitted data (they will try first to convert "+" to space, but find none, and then unescape the result ... and it comes out right). On the other hand, I am sure there is code in 'Javascript, The Definitive Guide" for DECODING responses and if the response is sent back 'www-form-encoded' one has to decode it properly (first change "+" to space and *then* unescape which will recover any "+"s in the original data).

Note from the Author or Editor:
In the first block of code on page 503, change these lines: name = encodeURIComponent(name.replace(" ", "+")); // Encode name value = encodeURIComponent(value.replace(" ", "+")); // Encode value To: name = encodeURIComponent(name).replace("%20", "+"); // Encode name value = encodeURIComponent(value).replace("%20", "+"); // Encode value In the last paragraph of page 503, cut the lines: HTML forms generate POST requests by default, but they can also make GET requests. (When the purpose...than POST.) And replace them with these: Form data can also be submitted using a GET request, and when the purpose of a form submission is to make a read-only query, GET is more appropriate than POST.

Anonymous  Jul 11, 2011  Aug 12, 2011
Printed
Page 674
starting comments in the code for 'display(state)'

... // initial state, in that case we would overwrite the acutal[SIC] historical (acutal -> actual) and ... (as an aside) 'is different from' differs from 'is different than.'

Note from the Author or Editor:
yes, fix the typo

Anonymous  Jul 16, 2011  Aug 12, 2011
Printed
Page 700
10th line of first example

In the 10th line of example there is comma missing after } (after third parameter of requestFileSystem).

Note from the Author or Editor:
Change these two lines: // Use fs here } To add a comma after the brace: // Use fs here },

Anonymous  Jul 06, 2011  Aug 12, 2011
PDF
Page 814
Part 3, Core JavaScript Reference, 2nd paragraph in Description part of Object.defineProperty()

The last sentence says that the default attribute values of absent members are false or null, but ECMAScript language defines them false or "undefined", not null. This definition is shown as Table-7 on ECMA-262 edition 5.1, within the Object Type section (8.6.1 actually).

Note from the Author or Editor:
Change "false or null" to "false or undefined"

a-shouko  Jul 20, 2011  Aug 12, 2011
Printed
Page 880
Last text paragraph on the page

The last sentence of the summary for ClientRect reads: ClientRect objects are x static: The 'x' appears to be a typo (if not, it isn't explained).

Note from the Author or Editor:
Change "x static" to "static" (delete the "x")

Joshua Davies  Mar 04, 2014 
Printed
Page 898
Last paragraph in the entry for Document

The last sentence of the last paragraph ends with: since there is an onDOMContentLoaded property This sentence should read: since there is no onDOMContentLoaded property

Note from the Author or Editor:
"there is an onDOMContentLoaded property" should be changed to "there is no onDOMContentLoaded property" as described in error.

Joshua Davies  Mar 05, 2014 
Printed
Page 922
explanation of dispatchEvent(Event event)

At least in 'WebKit' you need to call document.createEvent('Events') to create a simple event object (the book states that document.createEvent('event') will do).

Note from the Author or Editor:
Please fix.

Axel Schreiner  Aug 06, 2011  Aug 12, 2011
Other Digital Version
943
Description of min property of Input

The min property is described as "A maximum valid value for this Input element." This should probably say "A minimum valid ..."

Note from the Author or Editor:
Make change as in description of error: "A maximum valid value for this input. element." should become "A minimum valid value for this input. element.

Evan  Dec 15, 2011 
Printed
Page 983
First sentence on page

The first sentence reads: When the amount of work or time required to complete the task is not know, It should read: When the amount of work or time required to complete the task is not known,

Note from the Author or Editor:
Change "know" to "known"

Joshua Davies  Mar 20, 2014 
Printed, PDF
Page 1021
left column, line 13.

// and /” */ in comments, 23 should read // and /* */ in comments, 23

Note from the Author or Editor:
Please fix.

Mingway Huang  Jul 31, 2011  Aug 12, 2011
Printed, PDF
Page 1026
right column, line 2 from the bottom

"till or stroke using, 647" should read: "fill or stroke using, 647"

Note from the Author or Editor:
Please fix it.

Mingway Huang  Aug 01, 2011  Aug 12, 2011
Other Digital Version
2018
The page number above is the location number of Kindle edition

In the fuction "hide", a semicolon is missing in the following line: e.style.display = "non" // hide element and use its space

Note from the Author or Editor:
Line should read: e.style.display = "non"; // hide element and use its space

Yoshiki Shibata  Feb 04, 2013