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 |
| 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 |
|
| 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 |
| 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 |
|
| 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 |
| Printed |
Page 60
5th paragraph |
For "know then name" read "know the name".
|
Martin Leese |
Dec 30, 2012 |
|
| 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 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 |
| 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 |
| 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 |
| 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 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".
|
rachel.j |
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 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 |
| 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 |
|