Functional JavaScript

Errata for Functional JavaScript

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 xix
Last paragraph

I would also like to thank the O'Reilly staff who've helped me make this book better than I could have ever done alone: Mary Treseler, Melanie Yarbrough, Dan Fauxsmith, Meghan Connolly and Jasmine Kwityn.

Michael Fogus
Michael Fogus
O'Reilly Author 
Jun 20, 2013  Aug 02, 2013
Printed, PDF, ePub
Page 13
3rd Paragraph

Text states: "A comparator is a function that takes two values and returns <1 if the first is less than the second, >1 if it is greater, and 0 if they are equal." Should be less than or greater to zero, not one: "A comparator is a function that takes two values and returns <0 if the first is less than the second, >0 if it is greater, and 0 if they are equal."

Note from the Author or Editor:
More accuracy is better. Thank you.

Amanda Brown  Jun 25, 2013  Aug 02, 2013
Printed, PDF, ePub
Page 14
5th code sample

Code sample output is incorrect. Text states: [2, 3, -1, -6, 0, -108, 42, 10].sort(lessOrEqual); //=> [100, 10, 1, 0, -1, -1, -2] ... which would be correct if the array to be sorted matched the array in the code sample on page 15 using the comparator. Either the array to be sorted should contain the values: [100, 1, 0, 10, -1, -2, -1].sort(lessOrEqual); or the output should be: //=> [42, 10, 3, 2, 0, -1, -6, -108]

Amanda Brown  Jun 25, 2013  Aug 02, 2013
Printed
Page 14
Last paragraph

There is a reference to a function "lessThan" when the actual name is "lessOrEqual": "..., and lessThan only returns true or false, ...".

Note from the Author or Editor:
Thank you.

ThomasH  Jul 18, 2013  Aug 02, 2013
Printed
Page 18
footnote

"Simula" in the last word is missing capital letter.

Note from the Author or Editor:
The last word should rather be "simulation."

Ruben Verborgh  Jul 22, 2013  Aug 02, 2013
PDF
Page 32
Last code sample

The book claims that the following code will result in a global object: var bFunc = function () { return this }; var b = {name: "b", fun: bFunc}; b.fun(); //=> some global object, probably Window This is incorrect. In fact, b.fun() returns the object stored in the variable b. The semantics of this is such that this is set when the function is invoked, not when the function is defined. If the function is called using either b.fun() or b['fun'](), this is set to b.

Note from the Author or Editor:
This is definitely misleading. A more appropriate snippet would be: var bObj = {name: "b", fun: function(){ return this }}; bObj.fun(); //=> {name: "b", fun: function (){ return this }} var bFunc = bObj.fun; bFunc(); //=> some global object, probably Window The explanation text would then read as follows: Well, this might be surprising. You see, when a function is called within the context of an object, its this reference points to the object itself. However, when I later bound bFunc to the field bObj.fun, its reference was changed to the global object when called. In most programming languages offering...

AndersH  May 30, 2013  Aug 02, 2013
Printed, PDF, ePub
Page 35
United States

"On Speed" section - fourth code sample: function performTask(array) { _.each(array, function(elem) { doSomething(array[i]); }); } should be function performTask(array) { _.each(array, function(elem) { doSomething(elem); }); } (substitute "elem" for "array[i]" in call to doSomething)

Michael Martin  Jun 27, 2013  Aug 02, 2013
Printed, PDF, ePub
Page 48
Collection-Centric Programming - 3rd paragraph

In the spirit of completeness, itís worth noting that the function _.map can also take a third argument, the collection itself: Isn't this referring to the function *supplied* to _.map?

Note from the Author or Editor:
Yes. This should refer to the function that _.map takes.

Michael Martin  Jun 27, 2013  Aug 02, 2013
Printed
Page 50
last paragraph

The paragraph needs "just because a global variable holds a certain value [Ö] doesn't mean that when you refer to it you'll get the global value". This is incorrect: when you refer to any variable, you get its valueóby definition. However, what is probably meant is: "when you use the name of a global variable, it doesn't always point to that global variable (depending on the current scope)".

Note from the Author or Editor:
Changed to be a little more clear: ...doesn't mean that when you refer to its name you'll...

Ruben Verborgh  Jul 22, 2013  Aug 02, 2013
Printed
Page 63
last code example

The code var name = "Fogus"; var name = "Renamed"; name; is not an example of shadowing. There is only one variable name, whose value is simply changed from "Fogus" into "Renamed". The second "var" statement doesn't have any effect because a variable with that name has already been initialized, and due to hoisting, both declarations occur at the same time. The fragment is therefore equivalent to: var name = "Fogus"; name = "Renamed"; name; This can be verified by trying the following code: var name = "Fogus"; console.log(name); // "Fogus" var name; // If shadowing would occur, name would be undefined console.log(name); // still "Fogus"

Note from the Author or Editor:
Changed for clarity to "example to illustrate how shadowing variables works:"

Ruben Verborgh  Jul 22, 2013  Aug 02, 2013
Printed
Page 95
3rd paragraph

There is a reference to a function named "over10", whereas the previous page showed the definition of a function named "divide10by". It seems pretty likely that the name of the function was changed from "over10" to "divide10by" at some point, but not all references were caught.

David Howell  Jul 19, 2013  Aug 02, 2013
PDF
Page 145
Last code sample

The last implementation of `second` is defined as: ``` function second(a) { return _.first(_.first(a)); } ``` Taking the first element of the first element will not return the second element. Instead, I believe the author meant: ``` function second(a) { return _.first(_.rest(a)); } ```

beala  Jun 02, 2013  Aug 02, 2013
PDF
Page 157
1st code sample

The `enqueue` function defined on `Queue.prototype` uses the `+` operator to concatenate onto the end of the array `this._q`: ``` return new Queue(this._q + thing); ``` In JS, you cannot use `+` to concatenate onto arrays. Instead, you will get a string: [1,2,3]+1 === "1,2,31" Page 159 has a correct implementation (SaferQueue), which uses the `cat` function.

Note from the Author or Editor:
Thankfully this doesn't factor into the discussion, but in any case, the correct implementation is: Queue.prototype = { enqueue: function(thing) { return new Queue(cat(this._q, [thing])); } };

beala  Jun 02, 2013  Aug 02, 2013