Errata

JavaScript: The Good Parts

Errata for JavaScript: The Good Parts

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, PDF, ePub
Page 17
Chart at top of page

The line exiting && should curve up.

Also page 129.

Douglas Crockford
Douglas Crockford
 
Feb 25, 2013 
Other Digital Version
many
downloadable code examples

I would like to echo Rob Anderson's comment. The online example code is wrong in numerous places. One of the most egregious examples is the "Bad Example"/"Better Example" example on page 38/39.

The text on page 39 says: "Avoid creating functions within a loop. It can be wasteful computationally, and it can cause confusion, as we saw with the bad example."

The online "Better Example" has the function created within the loop.

Anonymous  Aug 09, 2012  Aug 14, 2012
Other Digital Version
1
Code Samples

The code samples provided at the following address contain numerous errors:

http://examples.oreilly.com/9780596517748/

I'm up to Chapter 4 and have found at least six examples so far where I have had to modify the code samples to match what is in the book so that they run. The good news is that errors have been picked up and corrected in the book, but the code samples have not been modified to match.

As I'm reading the mobi version in Kindle, there is no way to copy and paste the code samples directly from the book (this is disabled for me), so I am reliant on the external code sample files to be able to work through the examples.

Don't get me wrong, this is an excellent book - but the publisher's lack of attention in not updating the source code is disappointing.

Please update for future readers :)

Rob Anderson  Jul 14, 2012  Aug 14, 2012
Printed
Page 150, others
See description

The method() method is used in 15 or more places in the book, but the index lists it only once, and fails to list either of the places where method() is defined and explained. Without that, the implication is that it's a built-in JS function... unless one happens to have read the book in order, and remembered where it was defined.

Note from the Author or Editor:
The index should be corrected.

gwideman  Mar 29, 2012 
Printed, PDF, , Other Digital Version
Page Section B.7
Code sample

In section B.7, the C code:

for (p = src, q = dest; !*p; p++, q++) *q = *p;

must be replaced with:

for (p = src, q = dest; *p; p++, q++) *q = *p;

("*p" instead of "!*p")

Note from the Author or Editor:
The ! in this statement should be deleted.

Niklas Schm?cker  Feb 19, 2012 
Printed
Page 81
Function by

Where an object is thrown inside the else clause of the function by, the value of the message property ends with an erroneous semicolon ? this should be omitted.

Note from the Author or Editor:
In the middle of page 81, the semicolon after
+ name
should be deleted.

Thomas Ingram  Nov 25, 2011 
Printed
Page 123
Bottom of page

Delete

, or that method names are spelled correctly

Douglas Crockford
Douglas Crockford
 
Aug 03, 2011  Aug 26, 2011
Printed
Page 122
++ and --

In the last line of the paragraph, replace
prohibits
with
allows

Douglas Crockford
Douglas Crockford
 
Aug 03, 2011  Aug 26, 2011
Printed
Page 122
Top of page

Replace the second sentence with

There is a "Tolerate == and !=" (eqeq) option. Use of this option is not recommended.


== and != and eqeq are all monospace.

Douglas Crockford
Douglas Crockford
 
Aug 03, 2011 
Printed
Page 121
=

Delete

If you really intend an assignment, wrap it in another set of parentheses:

and the example that follows it.

Douglas Crockford
Douglas Crockford
 
Aug 03, 2011  Aug 26, 2011
PDF
Page 118
Top of page

/*members

should be

/*properties

Douglas Crockford
Douglas Crockford
 
Aug 03, 2011 
Printed
Page 117
Bottom of page

Replace Table C-1 with the table from http://www.jslint.com/lint.html#options

Douglas Crockford
Douglas Crockford
 
Aug 03, 2011 
Printed
Page 43
Last line of first example

tip('This box is resizeable.');

should be

.tip("This box is resizeable.");

Douglas Crockford
Douglas Crockford
 
Aug 03, 2011  Aug 26, 2011
Printed
Page 18
object literal train track

According to the diagram, the first part of an object literal can be a name or a string. However, string is never defined. Do you mean string literal, or are there other types of strings allowed.

Note from the Author or Editor:
In the object literal diagram on page 18 and also page 130, "string" should be "string literal".

rrs  Apr 08, 2011 
Other Digital Version
xiii
Downloadable code

Not only are the typo's not fixed here, whereas the are the printed version of the book.
Also running the code of the hanoi example in chapter 4 gives Illigal character.
It turns out, that the minus sign in textfile is an \uE288 but not \u002D.
There are 14 occurrences of this problem.

Note from the Author or Editor:
It is critical that \u002D be the code for minus sign in every code example.

Frank Sjoukes  Apr 07, 2011 
Printed
Page 29
Last line of first code listing

For consistency with the previous code listing, it would make sense to put the expected output of

document.writeln(myObject.value);

in a comment at the end of the line.

document.writeln(myObject.value); // 6

Note from the Author or Editor:
In the middle of the page, replace

document.writeln(myObject.value);

with

document.writeln(myObject.value); // 6

Duncan Parkes  Mar 17, 2011  Aug 26, 2011
Printed
Page 16
Errata

This is not really an error with the book, but an error in the errata.

The confirmed error on the last paragraph of page 16 is not an error - the text

'The && operator produces the value of its first operand if the first operand is *falsy*'

is correct.

Note from the Author or Editor:
This might be right. I can't see the incorrect errata.

Anonymous  Mar 16, 2011 
Printed
Page 17
infix operator diagram

In the infix operator diagram, to the right of the 'logical and' oval, the line meets the vertical line at a right angle. It should be curved upwards to indicate that this branch goes to the end of the diagram.

Note from the Author or Editor:
In the infix operator diagram on page 17 and also page 129, the track exiting (&&) should curve up to join instead of running straight into the line.

Duncan Parkes  Mar 16, 2011 
Printed
Page 129
literal (bottom)

The box that says [ function ] should say [ function literal ] .

Douglas Crockford
Douglas Crockford
 
Dec 20, 2010 
Printed
Page 106
Middle of page

Replace:

The arguments array is not an array; it is an object with a length member. That test will identify the arguments array as an array, which is sometimes what you want, even though arguments does not have any of the array methods. In any case, the test can still fail if the propertyIsEnumerable method is overridden.

with

The arguments array is not an array; it is an object with a length member. These tests will not identify the arguments array as an array.

Anonymous  Nov 04, 2010  Nov 01, 2010
Printed
Page 106
In the second code fragment

Replace

if (Array.prototype...

with

if (Object.prototype...

Anonymous  Nov 03, 2010  Nov 01, 2010
Printed
Page 37
In the code sample in the middle of the page


Wrap the invocation in parens.

var myObject = (function () {
and
}());

Anonymous  Nov 03, 2010  Nov 01, 2010
Printed
Page 118
Bottom of the page


At the bottom of the page there are two lists of operators. Please remove period from the first list and insert period after the ] in the second list.

, ; : { } and so on

) ] . ++ --

Anonymous  Nov 03, 2010  Nov 01, 2010
Printed
Page 140
The end of the third paragraph


At the end of the third paragraph, replace:

and will remain until JavaScript is replaced.

with

and will remain until JavaScript is replaced or repaired.

Anonymous  Nov 03, 2010  Nov 01, 2010
Printed
Page 106
Second code fragment


Replace the second code fragment with:

if (Array.prototype.toString.apply(my_value) === '[object Array]') {
// my_value is truly an array!
}

Anonymous  Nov 03, 2010  Nov 01, 2010
Printed
Page 113
Last line on page (code)

It should be:

}());

not

})();

Anonymous  Nov 03, 2010  Nov 01, 2010
Printed
Page 113
Last paragraph/last line

Replace

The workaround is to wrap the function expression in parentheses:

with

The workaround is to wrap the whole invocation in parentheses:

Anonymous  Nov 03, 2010  Nov 01, 2010
Printed
Page 109
The quote at the top of the page


On page 109, 'with me?' should be on the same line as 'which of my bad parts'.

which of my bad parts didst thou first fall in love with me?

Anonymous  Nov 03, 2010  Nov 01, 2010
Printed
Page 79
The [this.length, 0] statement


On page 79, the [this.length, 0] statement should all be on one line.

[this.length, 0].concat(Array.prototytpe.slice.apply(arguments)));

Anonymous  Nov 03, 2010  Nov 01, 2010
Printed
Page 71
The var my_regexp statement in the middle of the page


The var my_regexp statement in the middle of the page should be all on one line, and the line should end with a semicolon.

var my_regexp = new RegExp(I don't dare try to retype that stuff));

Anonymous  Nov 03, 2010  Nov 01, 2010
Printed
Page 55
Statement at the bottom of the page


On page 55, the type = statement at the bottom of the page should be all on one line.

type = typeof event === 'string' ? event : event.type;

Anonymous  Nov 03, 2010  Nov 01, 2010
Printed
Page 49
The return statement


On page 49, the return statement in 'get_name' should be all on one line.

return this.says() + ' ' + this.name + ' ' + this.says();

Anonymous  Nov 03, 2010  Nov 01, 2010
Printed
Page 42-43
The code example at the bottom

The line breaking style is wrong. Lines should be broken before '.' and not after. So move every '.' at the end of a line to the next line. So

getElement('myBoxDiv').
move(350, 150).

becomes

getElement('myBoxDiv')
.move(350, 150)
.

Douglas Crockford
Douglas Crockford
 
Oct 25, 2010  Nov 01, 2010
Printed
Page 37
9th line from bottom of page

In the last line of the 2nd-to-last paragraph, it reads, "... and those methods continue to enjoy the privilege of access to the value variable."

The word "value" should be in constant-width font, just as it is in the paragraph above.

Patrick Webster  Aug 05, 2010  Nov 01, 2010
PDF
Page 25
"string literal" railroad diagram

You can't make a string like "\n" using the "string literal" railroad diagram

Note from the Author or Editor:
The string literal diagram should be corrected.

fmaste  Jun 02, 2010 
Printed
Page 21
Retrieval

Under the Retrieval section:

a) "If the string expression is a constant, and ..."

`constant' should be replaced by `literal' to be consistent with the rest of the book. (Besides, strings are immutable (constant) anyway, right?)

b) "The undefined value is produced if an attempt is made to retrieve a nonexistent member:"

`member' should be replaced by `property' to be consistent with the rest of the book.

Note from the Author or Editor:
Change "If the string expression is a constant," to "If the string expression is a string literal,"

kovacs  Mar 25, 2010  Nov 01, 2010
Printed
Page 12
2nd para, last sentence (under `switch' diagram)

`default' should be in code font since it is a reserved word just as `switch' was in the first sentence of this same paragraph, i.e.:

The _switch_ statement...

...the optional _default_ statements...

kovacs  Mar 25, 2010  Nov 01, 2010
Printed
Page 9, 134
top diagram on both pages

Both string literal syntax diagrams incorrectly forbid an escaped character immediately before the closing quote. This is immedately contradicted by "\u0041" in the first example on page 9, May 2008 First Edition bought at Borders.

-----
Not sure I like the lightweight paper but thin is good.
-----
I suspect folks check "Post errata anonymously"
on autopilot as I did, just hitting each item
of the form in sequence. Try radio buttons.

Note from the Author or Editor:
The string literal diagram needs correction.

Devon Sean McCullough  Jan 17, 2010 
Printed
Page 39
first and second code examples

The lines of the introductory comments in both code examples on this page are too long for the printed version. The resulting line breaks cause invalid syntax due to the use of end-of-line comments.

The lines should be reformatted with shorter line length to avoid breaking as in the other examples in the book.

yacht  Nov 18, 2009  Apr 01, 2010
Printed
Page 18
first figure

Literal can be one of six literals.
5th box "function" should be "function literal".

Anonymous  Oct 08, 2009  Apr 01, 2010
Printed
Page 101
First line of text

(First prinitng, May 2008)

For "In this chapter", read "In this appendix"

Robert Hughes  Sep 13, 2009  Apr 01, 2010
Printed
Page 88
After the second line of code at the top of the page

(This error is in the first printing, May 2008.)

The last two tags have dropped out completely. The extended comment beginning

// Result:

on p.87 now finishes as follows on p.88 :

// [2] p
// [3]

It should finish like this :

// [2] p
// [3]

// [0] </body>
// [1] /
// [2] body
// [3]

// [0] </html>
// [1] /
// [2] html
// [3]

Robert Hughes  Sep 13, 2009  Apr 01, 2010
Printed
Page 86
Fifth line of code from the foot

(This error is in the first printing, May 2008.)

In the comments at the beginning of the code example at the foot of the page, instead of :

// [1] The tag name
// [2] The /, if there is one

Read :

// [1] The /, if there is one
// [2] The tag name

Robert Hughes  Sep 13, 2009  Apr 01, 2010
Printed
Page 83
Main code example, six lines from the end

(I have the first printing, May 2008)

The length of the array is not reset if delta > 0.

Instead of :

} else if (delta > 0) {
k = 1;
while (shift_count) {
this[new_len - k] = this[len - k];
k += 1;
shift_count -= 1;
}
}

Read :

} else if (delta > 0) {
k = 1;
while (shift_count) {
this[new_len - k] = this[len - k];
k += 1;
shift_count -= 1;
}
this.length = new_len;
}

Robert Hughes  Sep 12, 2009  Nov 01, 2010
Printed
Page 91
1st code block under string.split(separator, limit)

The text says:

var digits = '0123456789';
var a = digits.split('', 5);
// a is ['0', '1', '2', '3', '456789']

a is actually ['0', '1', '2', '3', '4']

Note from the Author or Editor:
// a is ['0', '1', '2', '3', '4']

Micah Stetson  Jul 09, 2009  Apr 01, 2010
Printed
Page 50
In the second example

Add "middle: m," on the line after "last: l,".

Douglas Crockford
Douglas Crockford
 
May 25, 2009  Apr 01, 2010
Printed
Page 16
in Table 2-1 replace "modulo" with "remainder"

Also make this replacement in the diagram called "infix operator" on page 17 and page 129.

Note from the Author or Editor:
In Table 2-1 replace "modulo" with "remainder".

Also make this replacement in the diagram called "infix operator" on page 17 and page 129.

Douglas Crockford
Douglas Crockford
 
May 22, 2009  Apr 01, 2010
Printed
Page 89
2nd paragraph

replace "localCompare" with "localeCompare"

Douglas Crockford
Douglas Crockford
 
May 19, 2009  Apr 01, 2010
Printed
Page 68
2/3rds down, paragraph that starts with Note

Replace "want we want" with "what we want".

Douglas Crockford
Douglas Crockford
 
May 18, 2009  Apr 01, 2010
Printed
Page 39
// BETTER EXAMPLE

The "BETTER EXAMPLE" is broken. The fix to the first printing was still incorrect. The example should read

var add_the_handlers = function (nodes){
var i;
for( i=0; i < nodes.length; i += 1 )
{
nodes[i].onclick = function(i){
return function () {
alert(i);
};
}(i);
}
};

That works with IE and Firefox.
This mistake is pretty bad, I would have hoped the author tested the code! Thanks

Note from the Author or Editor:
nodes[i].onclick = (function (i) {
return function (e) {
alert(i);
};
}(i));

Anonymous  Apr 09, 2009  Apr 01, 2010
Printed
Page 42
Code at top of page, third to last line


The wrong quote is used here. It should be the ASCII apostrophe: 'Q'

Anonymous  Apr 03, 2009  Apr 01, 2009
Printed
Page 117
Table C-1

Table C-1 does not jive with Options listed at http://www.jslint.com/#options ( and the JSLint Options listed at http://www.jslint.com/lint.html ) -- the latter has more options than Table C-1

In particular, Table C-1 is lacking:

newcap
css
indent
onevar
predef
regexp
safe
sidebar
strict
sub

Furthermore, Table C-1 lists "glovar," which does not appear in the JSLint Options listed at http://www.jslint.com/lint.html

Finally, there are 28 options listed in the JSLint Options at http://www.jslint.com/lint.html while there are only 26 at http://www.jslint.com/#options

Note from the Author or Editor:
Remove the line that starts with glovar.

kovacs  Mar 09, 2009  Apr 01, 2009
Printed
Page 74
middle

The edition of the book I have has a single character instead of the required `\u' for each of the four separate UniCode hex enumerations in the regular expression. This single character resembles a crescent moon and may be (or: is similar to) \u02D8.

Also, why is there a ' (single quote) character in the regular expression? ( It appears between FFFD and the closing ] )

In summary, the regex for var doubled_words should use the "simple letter class" from the first sentence of the first paragraph on the page.

Note from the Author or Editor:
The example has been mangled. The expression inside the [ ] should match the expression in the page's first sentence.

Anonymous  Mar 07, 2009  Apr 01, 2009
Printed
Page 33
Code near bottom of page

On page 33, the code at the top of the page includes `return this;' while the similar code at the bottom of the page is missing this statement.

Anonymous  Mar 07, 2009  Apr 01, 2009
Printed
Page 10
last sentence

In the last sentence of page 10, the word "then" should not be set in a constant width font since it is not a keyword; it should be italicized (like "truthy" in the same sentence was).

Anonymous  Mar 06, 2009  Apr 01, 2009
Printed
Page 41
first code sample (continued from page 40)

The syntax at the end of the sample is incorrect. It should end with:

}());

instead of

}();

because the result of the function invocation is the last parameter to the String.method call beginning on the previous page. This is particularly bad since the text immediately following asks the reader to pay special attention to the line with the error on it. The result is confusing.

Neal Tucker  Feb 24, 2009  Apr 01, 2009
Printed
Page 134
After diagram for throw statement

In the first printing of the book (May 2008), the diagram for the try statement is missing from Appendix D.

I do not know if this error was fixed in the September 2008 printing of the book.

This error has been fixed in the Safari Online edition of the book (viewed 2008 December 29).

Note from the Author or Editor:
The diagram for the try statement is missing.

Anonymous  Dec 29, 2008  Apr 01, 2009
Printed
Page 42
3rd line from bottom in code example on top of page

This line:

seqer.set_prefix('Q';)

should be:

seqer.set_prefix('Q');

Craig Doremus  Dec 29, 2008  Nov 01, 2008
Printed
Page 140
last section of code

Missing commas - replace last section with:

escapee = {

'"': '"',

'\\': '\\',

'/': '/',

b: 'b',

f: '\f',

n: '\n',

r: '\r',

t: '\t'

},

Anonymous  Nov 21, 2008  Apr 01, 2009
Printed
Page 71
line with new RegExp

the following:

new RegExp("\"(?:\\.|[^\\\\\\\"])*\"", 'g'))

should be the following:

new RegExp("\"(?:\\\\.|[^\\\\\\\"])*\"", 'g'))

Anonymous  Oct 24, 2008  Nov 01, 2008
54
second code block

This error is in the Print version and the Safari Online version. On Page 54, the second code block where the function "cat" is defined, the get_name method does not have a closing parenthesis.

var cat = function (spec) {
spec.saying = spec.saying || 'meow';
var that = mammal(spec);
that.purr = function (n) {
var i, s = '';
for (i = 0; i < n; i += 1) {
if (s) {
s += '-';
}
s += 'r';
}
return s;
};
that.get_name = function ( ) {
return that.says( ) + ' ' + spec.name +
' ' + that.says( );
return that;
};



The get_name function should be:

that.get_name = function ( ) {
return that.says( ) + ' ' + spec.name +
' ' + that.says( );
};
return that;

Note from the Author or Editor:
that.get_name = function () {
return that.says() + ' ' + spec.name +
' ' + that.says( );
};

Anonymous  Oct 22, 2008  Nov 01, 2008
4.12. Module
3rd code example

Hello,

The third source code block in this section on Safari Books Online has:

"seqer.set_prefix('Q';)"

replace with:

"seqer.set_prefix('Q');" //move semicolon outside of parenthesis.

It is easy to figure out, but still confusing if you Cut+Paste the code and it wont run.

Anonymous  Oct 21, 2008  Nov 01, 2008
Printed
Page 41
the last line of the deentityfy function example

The last line of the example reads:
}());
that is one closing parenthesis too many. It should be
}();
With the extra parenthesis the example will not run.

Anonymous  Oct 19, 2008  Nov 01, 2008
Printed
Page 29
end of first code example

The last line of code uses a getter:
myObject.getValue()
This getter has not been defined. So access the property directly as on the previous page:
myObject.value

Anonymous  Oct 18, 2008  Nov 01, 2008
Printed
Page 29
last line of the first code example [9/08]

the last line of the code example reads:
document.writeln(myObject.getValue()); // 6

this does not work, since the getValue() method is not defined on myObject. Safari 3.1.2 reports the error "TypeError: Value undefined (result of expression myObject.getValue) is not object." and Firefox 3 reports "Error: myObject.getValue is not a function".

The line should read:
document.writeln(myObject.value);
like in the code example on the previous page.

Anonymous  Oct 16, 2008  Nov 01, 2008
4.12
last code block

This line
seqer.set_prefix('Q';)
should be
seqer.set_prefix('Q');

Anonymous  Oct 14, 2008  Nov 01, 2008
Printed
Page 60
Last paragraph of "Delete" section

The book reads: "The property whose value is 'shi' has its key changed from '4' to '3'."

It should read: "from '3' to '2'."

Anonymous  Oct 12, 2008  Nov 01, 2008
Printed
Page 42
middle of the page

seqer.set_prefix('Q';)

should be

seqer.set_prefix('Q');

Douglas Crockford
Douglas Crockford
 
Oct 11, 2008  Nov 01, 2008
Printed
Page 42
code example on the top

There are two errors in this code example:
1) The definition of serial_maker is finished with () which invokes the anonymous function. That makes the next line: var seqer = serial_maker(); erroneous since serial_maker is not the function but the object returned by the anonymous function.
2) once the previous error is fixed the two lines:
seqer.set_prefix = 'Q';
seqer.set_seq = 10000;
should change to:
seqer.set_prefix('Q');
seqer.set_seq(10000);

Anonymous  Oct 10, 2008  Nov 01, 2008
Printed
Page 33
2nd Example: 'integer' method

Typo: Replace 'ceiling' by 'ceil':

Number.method('integer', function ( ) {
return Math[this < 0 ? 'ceil' : 'floor'](this);
});

Anonymous  Oct 09, 2008  Nov 01, 2008
Printed
Page 54
code example "var cat"

Missing
};
before
return that;
at end of function definition.

Note from the Author or Editor:
In the middle of the page.

that.get_name = function () {
return that.says() + ' ' + spec.name +
' ' + that.says();
};
return that;
}:

Anonymous  Oct 04, 2008  Nov 01, 2008
Printed
Page 21
First code sample under heading "Retrival"

The code reads:
stooge["first-name"] // "Joe"

However, on the previous (p. 20) the property "first-name" is set to "Jerome". To be consistent, both values should be the same.

Note from the Author or Editor:
It should be

stooge["first-name"] // "Jerome"

Anonymous  Oct 02, 2008  Nov 01, 2008
Printed
Page 54
In code in the middle of the page

The "that.get_name" method needs a closing curly bracket to end the function before the "return that;" statement.
The code as given:
that.get_name = function () {
return that.says() + ' ' + spec.name +
' ' + that.says();
return that;

The code should be:
that.get_name = function () {
return that.says() + ' ' + spec.name +
' ' + that.says();
};
return that;

Anonymous  Oct 01, 2008  Nov 01, 2008
Printed
Page 136
4th line

shoulddwell => should dwell

Douglas Crockford
Douglas Crockford
 
Sep 24, 2008  Nov 01, 2008
Printed
Page 90
3rd paragraph, string.replace sample for replacing an old phone area code

Hi,

Revision: First Edition
Page: 90

The 3rd paragraph on this page, which discusses string.replace, has the following code sample:

var oldareacode = /\((\d{3})\)/g;
var p = '(555)666-1212'.replace(oldareacode, '$1-');
// p is '555-555-1212'

The given answer is incorrect. var p is 555-666-1212.

Thanks for such a good book that is informative, intelligent and non-patronising. I hope O'Reilly and the author will publish more books like this!

Mark

Anonymous  Aug 19, 2008  Nov 01, 2008
Printed
Page 33
Second code example

In the function it is tried to invoke the method 'ceiling' on Math which will fail because the method is named 'ceil'.

So instead of

return Math[this < 0 ? 'ceiling' : 'floor'](this);

it should read

return Math[this < 0 ? 'ceil' : 'floor'](this);

Anonymous  Aug 12, 2008  Nov 01, 2008
Printed
Page 39
supposed corrected better example at 9780596517748.confirmed

from 9780596517748.confirmed

var add_the_handlers = function (nodes) {
var i;
for(i = 0; i < nodes.length; i += 1) {
nodes[i].onclick = function (i) {
return function (e) {
alert(e);
};
}(i);
}
};

where this alert e and not i

Notes from the Author: Replace alert(i) with alert(e)

I thought the point of the example was to be able to display the ordinal value of the node. Instead it displays "[object MouseEvent]" for FireFox, "undefined" for IE (since no event passed with onclick property assignment).

Note from the Author or Editor:
Replace alert(i) with alert(e)

Anonymous  Jul 25, 2008  Sep 01, 2008
Printed
Page 59
first paragraph, lines 8 and 12 (see line 2)

The name of an object is missing a letter
reads: number_object
should be: numbers_object

Note from the Author or Editor:
There are two places in the paragraph where number_object should be replaced with numbers_object

Anonymous  Jul 15, 2008  Sep 01, 2008
Printed
Page 59
1st paragraph

The original text follows:
--------------------------

The object literal:

var numbers_object = {
'0': 'zero', '1': 'one', '2': 'two',
'3': 'three', '4': 'four', '5': 'five',
'6': 'six', '7': 'seven', '8': 'eight',
'9': 'nine'
};

produces a similar result. Both numbers and number_object are objects containing 10 properties, and those properties have exactly the same names and values. But there are also significant differences. numbers inherits from Array.prototype, whereas number_object inherits from Object.prototype, so numbers inherits a larger set of useful methods. Also, numbers gets the mysterious length property, while number_object

-----------------------------
Original text is complete

The code names the array "numbers_object", the text refers to "number_object". It is true that this is only a 1 character typo, but fixing it ought to reduce potential confusion.

Anonymous  Jul 15, 2008  Sep 01, 2008
Printed
Page 74
3rd paragraph, regular expression example

The regular expression given in the example:

var doubled_words = /[A-Za-z\u00C0-\u1FFF\u2800-\uFFFD'\-]+\s+\1/gi;

does not include any capturing parens to allow the \1 backreference to work. I believe the corrected version should be:

var doubled_words = /([A-Za-z\u00C0-\u1FFF\u2800-\uFFFD'\-]+)\s+\1/gi;

Anonymous  Jul 07, 2008  Sep 01, 2008
Printed
Page 136
middle

JSON has six kinds of values:

Replace string with strings

Douglas Crockford
Douglas Crockford
 
Jun 30, 2008  Sep 01, 2008
Printed
Page 134
middle

Delete the first while diagram.

Note from the Author or Editor:
while was included twice.

Douglas Crockford
Douglas Crockford
 
Jun 30, 2008  Sep 01, 2008
Printed
Page 122
++ and --

replace

enabling to viruses

with

enabling viruses

Douglas Crockford
Douglas Crockford
 
Jun 30, 2008  Sep 01, 2008
Printed
Page 105
Last code example

Replace

function isNumber...

with

var isNumber = function isNumber(value) {
return typeof value === 'number' && isFinite(value);
};

Douglas Crockford
Douglas Crockford
 
Jun 30, 2008  Sep 01, 2008
Printed
Page 88
string.charAt(pos)

Replace

String.method('charAt', function () {
return this.slice(0, 1);
});

with


String.method('charAt', function (pos) {
return this.slice(pos, pos + 1);
});

Douglas Crockford
Douglas Crockford
 
Jun 30, 2008  Sep 01, 2008
Printed
Page 47
second code example

Replace

var that = Object.beget(this.prototype)

with

var that = Object.beget(this.prototype);

Note from the Author or Editor:
Add a semicolon.

Douglas Crockford
Douglas Crockford
 
Jun 30, 2008  Sep 01, 2008
Printed
Page 42
First code example

replace

seqer.set_prefix = 'Q';
seqer.set_seq = 1000;

with

seqer.set_prefix('Q');
seqer.set_seq(1000);

Douglas Crockford
Douglas Crockford
 
Jun 30, 2008  Sep 01, 2008
Printed
Page 37
Second paragraph

Replace getElementsByClassName with getElementsByAttribute

Douglas Crockford
Douglas Crockford
 
Jun 30, 2008  Sep 01, 2008
Printed
Page 64
second code example

Replace

return mat;
}

with

return mat;
};

Make this change in both places.

Note from the Author or Editor:
Add a semicolon.

Douglas Crockford
Douglas Crockford
 
Jun 30, 2008  Sep 01, 2008
Printed
Page 63
second code example

Replace

return a;
}

with

return a;
};

Note from the Author or Editor:
Add a semicolon.

Douglas Crockford
Douglas Crockford
 
Jun 30, 2008  Sep 01, 2008
Printed
Page 52
last line of code example

Replace

}

with

};

Note from the Author or Editor:
Add a semicolon.

Douglas Crockford
Douglas Crockford
 
Jun 30, 2008  Sep 01, 2008
Printed
Page 39
First code example

Replace

}
}
};

with

};
}
};

Note from the Author or Editor:
Add a semicolon.

Douglas Crockford
Douglas Crockford
 
Jun 30, 2008  Sep 01, 2008
Printed
Page 37
First code example

Replace

}
}

with

}
};

Note from the Author or Editor:
Add a semicolon.

Douglas Crockford
Douglas Crockford
 
Jun 30, 2008  Sep 01, 2008
Printed
Page 34
First code example

Replace

}
}

with

}
};

Note from the Author or Editor:
Add a semicolon.

Douglas Crockford
Douglas Crockford
 
Jun 30, 2008  Sep 01, 2008
Printed
Page 32
first code example

Replace

}
}

with

};
}

Note from the Author or Editor:
Add a semicolon.

Douglas Crockford
Douglas Crockford
 
Jun 30, 2008  Sep 01, 2008
Printed
Page 29
First code example

Replace

that.value = add(that.value, that.value)

with

that.value = add(that.value, that.value);

Note from the Author or Editor:
Add a semicolon.

Douglas Crockford
Douglas Crockford
 
Jun 30, 2008  Sep 01, 2008
Printed
Page 28
First code example

value: 0;

should be

value: 0,

Note from the Author or Editor:
Change the semicolon to a comma.

Douglas Crockford
Douglas Crockford
 
Jun 30, 2008  Sep 01, 2008
Printed
Page 24
second code example

The last two lines of the example are
}
}

Delete the next to last line:

}

Douglas Crockford
Douglas Crockford
 
Jun 30, 2008  Sep 01, 2008
Printed
Page 13
in the code sample

hasownProperty should be hasOwnProperty

Douglas Crockford
Douglas Crockford
 
Jun 30, 2008  Sep 01, 2008
Printed
Page 10
Last paragraph, first sentence

'based in' should be 'based on'.

Douglas Crockford
Douglas Crockford
 
Jun 30, 2008  Sep 01, 2008
Printed
Page xiii
Acknowledgments

LeComte should be Lecompte (no camelCase).

Note from the Author or Editor:
Lecomte not Lecompte

Douglas Crockford
Douglas Crockford
 
Jun 30, 2008  Sep 01, 2008
Printed
Page 39
BETTER EXAMPLE portion of code

var add_the_handlers = function (nodes) {
var i;
for(i = 0; i < nodes.length; i += 1) {
nodes[i].onclick = function (i) {
return function (e) {
alert(i);
};
}(i);
}
};

should be

var add_the_handlers = function (nodes) {
var i;
for(i = 0; i < nodes.length; i += 1) {
nodes[i].onclick = function (i) {
return function (e) {
alert(e);
};
}(i);
}
};

where this alert e and not i

Note from the Author or Editor:
Replace alert(i) with alert(e)

Anonymous  Jun 21, 2008  Sep 01, 2008
Printed
Page 69
Bottom footnote

In the press them all together regex, there's an extra ? (between the ) and ( )
... a-z]+)?(?::( ...

or there's a ? missing from the
var parse_url = ... on page 66.

Note from the Author or Editor:
Replace +)?(?:: with +)(?:: by deleting the ? between the parens.

Anonymous  Jun 10, 2008  Sep 01, 2008
Printed
Page 42
code example

The variable should hold the function value, not the object returned by a call to the function. Instead of:

var serial_maker = function () {
/* detail omitted */
}();
var seqer = serial_maker();

The code should read:

var serial_maker = function () {
/* detail omitted */
};
var seqer = serial_maker();

Anonymous  Jun 07, 2008  Sep 01, 2008
Printed
Page 32
last line of the second example

tryIt should be try_it

Anonymous  Jun 06, 2008  Sep 01, 2008
Printed
Page 51
first code example

return this.says + ' ' + this.name + ' ' + this.says;

apparently should be:

return this.says() + ' ' + this.name + ' ' + this.says();

like the similar correct example on page 49.

Anonymous  Jun 04, 2008  Sep 01, 2008
Printed
Page 47
4th line of code in middle of page

The code listing on page 47 of Crockford's book Javascript - The Good Parts is missing a semicolon, namely:

// Create a new object that inherits from the
// constructor's prototype

var that = Object.beget(this.prototype)

Anonymous  Jun 03, 2008  Sep 01, 2008
Printed
Page 41-42
code example beginning on page 41 and continuing on 42

code example should read:
var serial_maker = function() {
var prefix = '';
var seq = 0;
return {
set_prefix: function (p) {
prefix = String(p);
},
set_seq: function (s) {
seq = s;
},
gensym: function(){
var result = prefix + seq;
seq += 1;
return result;
}
};
} // need to remove the (); here otherwise serial_maker cannot be called.


var seqer = serial_maker();
seqer.set_prefix('Q'); // this line previously read seqer.set_prefix = 'Q';
seqer.set_seq (1000); // this line previously read seqer.set_seq = 1000;
var unique = seqer.gensym();


in particular, the current printed version returns an object, but seqer cannot equal serial_maker(); That is, either the parens happen at the function definition or they happen at the assignment, but they cannot happen at both.

also, the code example assigns values to setters, the correction uses the setters instead of overwriting them.

Anonymous  Jun 03, 2008  Sep 01, 2008
Printed
Page Section 4.6
second block of code

the function declaration is named try_it, but it then tries to call the function by tryIt().

Anonymous  Jun 02, 2008  Sep 01, 2008
Printed
Page 64
Code block after 1st paragraph

From the context, it seems this part:

for (j = 0; j < n; j += 1) {
a[j] = 0;
}

should be:

for (j = 0; j < n; j += 1) {
a[j] = initial;
}

- otherwise the "initial" parameter is quite pointless.

Anonymous  Jun 02, 2008  Sep 01, 2008
Printed
Page 42
End of first code block, the definition of serial_maker

The serial_maker function should not be invoked when it is defined. Invoking it as shown in the book sets serial_maker to reference an object with 3 methods. The subsequent statement:

var seqer = serial_maker();

makes no sense since serial_maker is not a function.

You should remove the function invocation at the end of the serial_maker definition for the example to make sense.

Note from the Author or Editor:
Replace the line

}();

with

};

Anonymous  May 27, 2008  Sep 01, 2008
Printed
Page 32
2nd code sample

The last line of the code sample should reads:
tryIt();
instead it should read:
try_it();
since this is the name of the variable in which the function defined in the sample is stored.

Anonymous  May 26, 2008  Sep 01, 2008
Printed
Page 98
next to last line

'firortranst' should be 'first'

Douglas Crockford
Douglas Crockford
 
May 15, 2008  Sep 01, 2008
Printed
Page xiii

Location: Acknowledgments

Description: LeComte should be Lecompte (no camelCase).

Anonymous    Sep 01, 2008
Printed
Page 10

Location: Last paragraph, first sentence

Description: 'based in' should be 'based on'.

Anonymous    Sep 01, 2008
Printed
Page 13

Location: in the code sample

Description: hasownProperty should be hasOwnProperty

Anonymous    Sep 01, 2008
Printed
Page 22

Location: under Prototype, second paragraph, third line and in code below it

Changed beget to create

Anonymous    Sep 01, 2008
Printed
Page 23

Location: second code line at the top of page

Changed beget to create

Anonymous    Sep 01, 2008
Printed
Page 24

Location: second code example

Description: The last two lines of the example are
}
}

Delete the next to last line:

}


Anonymous    Sep 01, 2008
Printed
Page 28

Location: First code example

Description: value: 0;

should be

value: 0,

Notes from the Author: Change the semicolon to a comma.

Anonymous    Sep 01, 2008
Printed
Page 29

Location: First code example

Description: Replace

that.value = add(that.value, that.value)

with

that.value = add(that.value, that.value);

Notes from the Author: Add a semicolon.

Anonymous    Sep 01, 2008
Printed
Page 32

Location: first code example

Description: Replace

}
}

with

};
}

Notes from the Author: Add a semicolon.

Anonymous    Sep 01, 2008
Printed
Page 32

Location: 2nd code sample

Description: The last line of the code sample should reads:

tryIt();

instead it should read:

try_it();

since this is the name of the variable in which the function defined
in the sample is stored.

Anonymous    Sep 01, 2008
Printed
Page 34

Location: First code example

Description: Replace

}
}

with

}
};

Notes from the Author: Add a semicolon.

Anonymous    Sep 01, 2008
Printed
Page 37

Location: First code example

Description: Replace

}
}

with

}
};

Notes from the Author: Add a semicolon.

Anonymous    Sep 01, 2008
Printed
Page 37

Location: Second paragraph

Description: Replace getElementsByClassName with getElementsByAttribute

Anonymous    Sep 01, 2008
Printed
Page 39

Location: First code example

Description: Replace

}
}
};

with

};
}
};

Notes from the Author: Add a semicolon.

Anonymous    Sep 01, 2008
Printed
Page 39

Location: BETTER EXAMPLE portion of code

Description: var add_the_handlers = function (nodes) {
var i;
for(i = 0; i < nodes.length; i += 1) {
nodes[i].onclick = function (i) {
return function (e) {
alert(i);
};
}(i);
}
};

should be

var add_the_handlers = function (nodes) {
var i;
for(i = 0; i < nodes.length; i += 1) {
nodes[i].onclick = function (i) {
return function (e) {
alert(e);
};
}(i);
}
};

where this alert e and not i

Replaced alert(i) with alert(e)

Anonymous    Sep 01, 2008
Printed
Page 41-42

Location: code example beginning on page 41 and continuing on 42

Description: code example should read:

var serial_maker = function() {
var prefix = '';
var seq = 0;
return {
set_prefix: function (p) {
prefix = String(p);
},
set_seq: function (s) {
seq = s;
},
gensym: function(){
var result = prefix + seq;
seq += 1;
return result;
}
};
} // need to remove the (); here otherwise serial_maker cannot be called.

var seqer = serial_maker();
seqer.set_prefix('Q'); // this line previously read seqer.set_prefix
= 'Q';
seqer.set_seq (1000); // this line previously read seqer.set_seq = 1000;
var unique = seqer.gensym();

in particular, the current printed version returns an object, but
seqer cannot equal serial_maker(); That is, either the parens happen
at the function definition or they happen at the assignment, but they
cannot happen at both.

Also, the code example assigns values to setters, the correction uses
the setters instead of overwriting them.

Anonymous    Sep 01, 2008
Printed
Page 42

Location: code example

Description: The variable should hold the function value, not the
object returned by a call to the function. Instead of:

var serial_maker = function () {
/* detail omitted */
}();
var seqer = serial_maker();

The code should read:

var serial_maker = function () {
/* detail omitted */
};
var seqer = serial_maker();

Anonymous    Sep 01, 2008
Printed
Page 42

Location: First code example

Description: replace

seqer.set_prefix = 'Q';
seqer.set_seq = 1000;

with

seqer.set_prefix('Q');
seqer.set_seq(1000);

Anonymous    Sep 01, 2008
Printed
Page 42

Location: End of first code block, the definition of serial_maker

Description: The serial_maker function should not be invoked when it
is defined. Invoking it as shown in the book sets serial_maker to
reference an object with 3 methods. The subsequent statement:

var seqer = serial_maker();

makes no sense since serial_maker is not a function.

You should remove the function invocation at the end of the
serial_maker definition for the example to make sense.

Notes from the Author: Replace the line

}();

with

};

Anonymous    Sep 01, 2008
Printed
Page 47

Location: second code example

Description: Replace

var that = Object.beget(this.prototype)

with

var that = Object.beget(this.prototype);

Notes from the Author: Add a semicolon.

Anonymous    Sep 01, 2008
Printed
Page 47

Location: 4th line of code in middle of page

Description: The code listing
Javascript - The Good Parts is missing a semicolon, namely:

// Create a new object that inherits from the
// constructor's prototype

var that = Object.beget(this.prototype)

Anonymous    Sep 01, 2008
Printed
Page 51

Location: first code example

Description: return this.says + ' ' + this.name + ' ' + this.says;

apparently should be:

return this.says() + ' ' + this.name + ' ' + this.says();

like the similar correct example on page 49.

Anonymous    Sep 01, 2008
Printed
Page 51

Description: second line, first line of code, 10th line of code from the bottom,

Changed beget to create

Anonymous    Sep 01, 2008
Printed
Page 52

Location: last line of code example

Description: Replace

}

with

};

Notes from the Author: Add a semicolon.

Anonymous    Sep 01, 2008
Printed
Page 52

Description: 14th line from top

Changed beget to create

Anonymous    Sep 01, 2008
Printed
Page 53

Description: 12th line from top

Changed beget to create

Anonymous    Sep 01, 2008
Printed
Page 59

First paragraph, lines 8 and 12 (see line 2)

The name of an object was missing a letter

was: number_object
now reads: numbers_object

There are two places in the paragraph where number_object should be replaced with
numbers_object

Anonymous    Sep 01, 2008
Printed
Page 63

Location: second code example

Description: Replace

return a;
}

with

return a;
};

Notes from the Author: Add a semicolon.

Anonymous    Sep 01, 2008
Printed
Page 63

Description: 9th line from top

Changed beget to create

Anonymous    Sep 01, 2008
Printed
Page 64

Location: second code example

Description: Replace

return mat;
}

with

return mat;
};

Make this change in both places.

Notes from the Author: Add a semicolon.

Anonymous    Sep 01, 2008
Printed
Page 64

Location: Code block after 1st paragraph

Description: From the context, it seems this part:

for (j = 0; j < n; j += 1) {
a[j] = 0;
}

should be:

for (j = 0; j < n; j += 1) {
a[j] = initial;
}

- otherwise the "initial" parameter is quite pointless.

Anonymous    Sep 01, 2008
Printed
Page 69

Location: Bottom footnote

Description: In the press them all together regex, there's an extra ?
(between the ) and ( )
... a-z]+)?(?::( ...

or there's a ? missing from the
var parse_url = ... on page 66.

Notes from the Author: Replace +)?(?:: with +)(?:: by deleting the ?
between the parens.

Anonymous    Sep 01, 2008
Printed
Page 74

3rd paragraph, regular expression example
The regular expression given in the example:

var doubled_words = /[A-Za-zu00C0-u1FFFu2800-uFFFD'-]+s+1/gi;

does not include any capturing parens to allow the 1 backreference to work. Corrected version
now reads:

var doubled_words = /([A-Za-zu00C0-u1FFFu2800-uFFFD'-]+)s+1/gi;

Anonymous    Sep 01, 2008
Printed
Page 86

Description: under Object, second line of code

Changed beget to create

Anonymous    Sep 01, 2008
Printed
Page 88

Location: string.charAt(pos)

Description: Replace

String.method('charAt', function () {
return this.slice(0, 1);
});

with

String.method('charAt', function (pos) {
return this.slice(pos, pos + 1);
});

Anonymous    Sep 01, 2008
Printed
Page 98

Location: next to last line
Description: 'firortranst' should be 'first'

Anonymous    Sep 01, 2008
Printed
Page 105

Location: Last code example

Description: Replace

function isNumber...

with

var isNumber = function isNumber(value) {
return typeof value === 'number' && isFinite(value);
};

Anonymous    Sep 01, 2008
Printed
Page 122

Location: ++ and --

Description: replace

enabling to viruses

with

enabling viruses

Anonymous    Sep 01, 2008
Printed
Page 134

Location: middle

Description: Delete the first while diagram.

Notes from the Author: while was included twice.

Anonymous    Sep 01, 2008
Printed
Page 136

Location: middle

Description: JSON has six kinds of values:

Replace string with strings

Anonymous    Sep 01, 2008
Printed
Page 147

Description: under arrays

Object.beget method changed to Object.create method

Anonymous    Sep 01, 2008
Printed
Page 151

Description: Object.beget method changed to Object.create method

Anonymous    Sep 01, 2008