Errata

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
 
Jun 20, 2013  Aug 02, 2013
Printed
Page xi
3rd paragraph

"functonal" should be "functional" in:
"This growth is due to the observation that functonal programming appears to help..."

Note from the Author or Editor:
functonal" should be "functional"

Anonymous  Sep 06, 2013  Aug 08, 2014
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 23
2nd paragraph

look at the following code
var array123 = [1,2,3,4,5];
for (var i = 0, l = array123.length; i < l; i++) {
doSomething(array[i]);
}

at doSomething there should be array123[i] instead of array[i]

Note from the Author or Editor:
should be array123[i]

Anonymous  Jun 15, 2014  Aug 08, 2014
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...

Anders Hessellund Jensen  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 62
footnote 10

"I go more in depth in Chapter 3". Chapter 4 is the one covering higher-order functions (and we are in Chapter 3).

Note from the Author or Editor:
Change to "I go more in depth in Chapter 4"

fmdkdd  Mar 28, 2014  Aug 08, 2014
Printed
Page 62
2nd paragraph and code example below

function makeAdder(CAPTURED) {
return function(free) {
return free + CAPTURED;
};
}

In the code example, `free` is a parameter to the inner function, hence it is bound, not ?free?. `CAPTURED` is free in the inner function, and it is ?captured? by the same function.

Note from the Author or Editor:
free was meant to be the opposite of CAPTURED, but you point out that it muddies the point WRT "free variable." A better name for free could be used, perhaps just x or other.

fmdkdd  Mar 28, 2014  Aug 08, 2014
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 64
3rd paragraph

"If you guessed the value returned value of ..." there's an extra "value" in there.

Note from the Author or Editor:
remove first "value"

fmdkdd  Mar 28, 2014  Aug 08, 2014
Printed
Page 65
Last paragraph

The second-last sentence reads "Since I created a new reference for isEven by creating a fresh *variable*, ...". I think it is not a fresh variable you created, but a fresh value that is assigned to an existing variable. Hence isOdd is not affected, as it closed over the old value.

Note from the Author or Editor:
Change "Since I created a new reference for isEven by creating a fresh *variable*, ..." to "Since I created a a fresh value that is assigned to an existing variable..."

ThomasH  Aug 10, 2013  Aug 08, 2014
Printed
Page 69
first paragraph and bullet list

A higher-order function does not have to be first-class (though it usually is). So ?first-class? does not define ?higher-order? so much as it enables it.

Also, Chapter 2 (page 28, bottom bullets) says that a higher-order function can do one or both (taking and returning a function). Here it seems it should always be both, which is unnecessarily restricting.

Note from the Author or Editor:
The list is meant to imply OR, but that is not clear from the lead-in text.

fmdkdd  Mar 28, 2014  Aug 08, 2014
Printed
Page 71
Start of second paragraph

The paragraph starts with "..., we can now use finder to *find* different types of "best-fit" functions:". It should probably read "...use finder to *use* different types ...", as the best-fit function is one of its parameters, not its result.

Note from the Author or Editor:
Change to "...use finder to *use* different types ..."

ThomasH  Aug 10, 2013  Aug 08, 2014
Printed
Page 71
1st paragraph

The first paragraph ends with "... to think in terms of functions, even when the best value is a value itself." I'm struggling with the entire last part, particularly with the word "best".

For one thing I thought the point was to favor functions over values, so I would have expected something like "..., even when the return value is the passed value itself". This would go nicely with the use of _.identity as the valueFun in the preceeding code example.

For another thing "best value" allures to the "bestFun" parameter of the function definition, which takes two values and returns the better of them. But this has nothing to do with the use of the _.identity function in the sample which seems to be the topic of the paragraph!?

And in general, how could the best value not be a value?!

Note from the Author or Editor:
The last part of the sentence stating ", even when the best value is a value itself." should probably be removed.

ThomasH  Aug 10, 2013  Aug 08, 2014
PDF
Page 90
Whole page

The result of performCommandHardcoded and performCommand by dispatch high-order function are different.

var performCommand = dispatch(
isa('notify', function(obj) { return notify(obj.message) }),
isa('join',function(obj) { return changeView(obj.target) }),
function(obj) { alert(obj.type) });

if the object type is 'notify', and isa will return a function, but
if notify(object,message) invocation returns null or undefined, then the next function will be invoked. so in the end, function(obj){alert(obj.type)} will be called in the end.

Note from the Author or Editor:
A robustness check in dispatch used before calling a function/method would be useful.

simon  Sep 25, 2013 
Printed
Page 91
4th line

?you would need to go in and changed the actual switch statement? -> replace "changed" by "change".

Note from the Author or Editor:
replace "changed" by "change"

fmdkdd  Mar 28, 2014  Aug 08, 2014
PDF
Page 94
Poland

In the "Curry to the right, curry to the left" it says:

"The use of a division operation to illustrate currying works nicely because the result changes if the arguments are switched (i.e., it?s not associative)."

Indeed division is not associative, but isn't it more intuitive in this context to state about division being not commutative?

Note from the Author or Editor:
Yes, commutativity is correct.

Przemys&#322;aw W&#281;grzyn  Aug 14, 2013  Aug 08, 2014
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
Printed
Page 99
1st paragraph after "Currying for Fluent APIs" heading

First sentence "... very often lead to fluent ..." should read "... very often leads to fluent ...".

Note from the Author or Editor:
First sentence "... very often lead to fluent ..." should read "... very often leads to fluent ...".

ThomasH  Aug 12, 2013  Aug 08, 2014
Printed
Page 103
last paragraph

"...be aware that a number that you're attempting ..." =>
"...be aware that a function that you're attempting ..."

Note from the Author or Editor:
Change to "...be aware that a function that you're attempting ..."

ThomasH  Aug 12, 2013  Aug 08, 2014
Printed
Page 103
`partial2` code example

Missing `_.toArray` around `arguments` in `cat` call of the inner anonymous function. Using _.union instead of cat would have worked with the raw arguments object.

Note from the Author or Editor:
Call _.toArray on arguments supplied to cat.

fmdkdd  Mar 28, 2014  Aug 08, 2014
Printed
Page 104
2nd paragraph, 3rd paragraph

Text:
-----------
Recall the validator function from Chapter 4:

validator("arg must be a map", aMap)(42);
//=> false

The validator higher order function takes a validation predicate and returns an array of the errors encountered along the way. If the error array is empty, then there were no reported errors.
-----------
The validator function is given bottom of page 83. It takes an error string and a predicate, and returns the wrapped predicate with its message property set to the supplied error string.

The checker function, defined page 82, accepts validator functions and returns a function that returns an array of errors.

The text that follows seems to deal with validator as it is defined on p83, rather than as it is described on page 104.

Note from the Author or Editor:
The fragment "an array of the errors encountered along the way. If the error array is empty, then there were no reported errors." can be changed to "an augmented predicate useful in the operation of the checker function."

Will Watts  Jun 21, 2014  Aug 08, 2014
PDF
Page 107
Last code sample

The function that is called should be createLaunchCommand() and not createCommand()

Note from the Author or Editor:
The function that is called should be createLaunchCommand() and not createCommand()

Justus Sturkenboom  Aug 11, 2013  Aug 08, 2014
Printed
Page 109
3rd code example

Replace
function(str) { return !str }
by
function(x) { return !x }

for consistency with the previous example.

Note from the Author or Editor:
Replace
function(str) { return !str }
by
function(x) { return !x }

fmdkdd  Mar 28, 2014  Aug 08, 2014
Printed
Page 116
2nd paragraph, last line

"and the base case `zipped`" replace `zipped` by `zipped1`.

Note from the Author or Editor:
replace `zipped` by `zipped1`.

fmdkdd  Mar 28, 2014  Aug 08, 2014
Printed
Page 118
figure

Since there is not path from Lua to JS, it does not belong to ?programming languages that have influenced JavaScript either directly or indirectly?.

Note from the Author or Editor:
It's there so that searching for JS influences does not list Lua. That said, the phrase "directly or indirectly" can be changed to "directly, indirectly, or not at all."

fmdkdd  Mar 28, 2014  Aug 08, 2014
Printed
Page 126
2nd paragraph

Should add a note saying that `deepClone` is far from a complete solution to deep cloning objects in JS. It doesn�t clone functions, even shallowly.

Note from the Author or Editor:
I'm not sure I would want to allow cloning of functions -- indeed, what would you be cloning? In any case, you're probably right that a footnote making a point of the limitations would be useful.

fmdkdd  Mar 28, 2014  Aug 08, 2014
Printed
Page 137
2nd paragraph

"Not only does ... influence*s* require far less code," =>
"Not only does ... influence*d* require far less code,"

(As a footnote, I might add that it is also less general, as it bakes in the two-level nested array structure of 'influences'. But that would take away from the nice point about function composition that you are making in this paragraph.)

ThomasH  Aug 13, 2013  Aug 08, 2014
PDF
Page 139
Last line.

The randString function will only output random lowercase ASCII characters including "q". It will not output "r", "s", "t", "u", "v", "w", "x", "y", "z". Last line on page 139 should be changed to:

var ascii = repeatedly(len, partial1(rand, 35));

Note from the Author or Editor:
Change partial1(rand, 26 to partial1(rand, 35))

Knut Kristian Johansen  Oct 27, 2013  Aug 08, 2014
PDF
Page 141
top of page

The Jasmin expectation at the bottom of p140 is duplicated at the top of p141.

Note from the Author or Editor:
The snippet of code as follows can be removed / ignored:

{
expect(_.map([1,2,3], sqr)).toEqual([1, 4, 9]);
});
});

Cort Spellman  Jul 24, 2014  Aug 08, 2014
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));
}
```

Alex Beal  Jun 02, 2013  Aug 02, 2013
PDF
Page 154
Paragraph 2.

The result of:

var a = repeatedly(1000, partial1(rand, 3));

Is more like {1: 327, 2: 336, 3: 337} than the result in the book which is {1: 498, 2: 502}.

Note from the Author or Editor:
Change partial1(rand, 3) to partial1(rand, 2)

Knut Kristian Johansen  Oct 27, 2013  Aug 08, 2014
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]));
}
};

Alex Beal  Jun 02, 2013  Aug 02, 2013
PDF
Page 157
Last paragraph.

The number 10000 is pushed to seed, but the _q member of instance q now has a new 1000, not 10000 as expected.

Note from the Author or Editor:
Change 1000 to 10000

Knut Kristian Johansen  Oct 27, 2013  Aug 08, 2014
Printed
Page 160
last paragraph

I'm struggling with this sentence, broken up for clarity (non-native speaker here):

[1] "When you pass around mutable objects and modify them within one function
[2] to another method
[3] to a global scope,
[4] you're effectively lifted
[5] the effect of any change
[6] relevant to your changed object
[7] to affecting the program as a whole."

What does "pass"[1] refer to, "to another method"[2] or "to a global scope"[3]?
Then what does the other refer back to, "modify them"?
Or is it simply missing an "or" and should read "to another method or to a global scope"?
And what is "the effect of any change relevant to your changed object"[5][6]?
An unrelated change that occurs after the object has been changed?
Or should it be just "the effect of any change to your object"?

I've tried to use figure 7-3 on the same page to disentangle this, but how should the figure be read? On p.148 you speak of showing "dependencies created by points of mutation". So every gray-background square in the figure is a point of mutation of the same object, right?!
Then what do the edges express? Do they read "change influences the behavior of"? So the change made in x influences z? Would this change also propagate to f, or is f only affected by another change made in z, and independent of the first change made in x?
What does it mean that some borders of boxes and edges are solid, while others are dashed?


Note from the Author or Editor:
Another (and better) way of phrasing this sentence:

Any time that you pass around a mutable object from one function to another and make changes to it along the way, the effects are never local to each function but are instead global effects.

As for the other questions:

Yes, every gray-background square in the figure is a point of mutation of the same object. All of the lines represent dependencies, but only the dotted lines are changes.

ThomasH  Aug 15, 2013  Aug 08, 2014
PDF
Page 167
The 3rd code sample on the page

ACTUAL TEXT:
_.tap([1,2,3], note);
;; NOTE: 1,2,3
//=> [1, 2, 3]


EXPECTED TEXT:
_.tap([1,2,3], note);
// NOTE: 1,2,3
//=> [1, 2, 3]


NOTICE:
The difference is `//` vs `;;` on the second line

Note from the Author or Editor:
Whoops. Some Clojure snuck in there. Change to // NOTE: 1,2,3

itod47  Jan 17, 2014  Aug 08, 2014
Printed
Page 167
2nd paragraph, 1st line

"With the use of _.result" replace `_.result` by `_.value`.

Note from the Author or Editor:
replace `_.result` by `_.value`.

fmdkdd  Mar 28, 2014  Aug 08, 2014
Printed
Page 168
3rd paragraph, last sentence

"What I mean by what" replace second "what" by "that".

Note from the Author or Editor:
replace second "what" by "that".

fmdkdd  Mar 28, 2014  Aug 08, 2014
Printed
Page 193
middle of page

"The implementation of lazyChain is shown here:" =>
"The use of lazyChain is shown here:"

Note from the Author or Editor:
Change to: "The use of lazyChain is shown here:"

ThomasH  Aug 16, 2013  Aug 08, 2014
PDF
Page 210
Paragraph 1.

"That is, by using _.extend, I copy all of the methods into Hole.mix
in."

should be:

That is, by using _.extend, I copy all of the methods into Hole.prototype.

Note from the Author or Editor:
Change to Hole.prototype

Knut Kristian Johansen  Oct 27, 2013  Aug 08, 2014
Printed
Page 224
United Kingdom

The line:

# (console) Hello CoffeeScript

Should have an exclamation mark at the end of it.

Note from the Author or Editor:
# (console) Hello CoffeeScript

Should have an exclamation mark at the end of it.

Mike Grundel  Oct 01, 2013  Aug 08, 2014
PDF
Page 229
Blog Posts

"Monads are Tress with Grafting" should be "Monads are Trees with Grafting"

Note from the Author or Editor:
should be "Monads are Trees with Grafting"

Tim King
 
Aug 12, 2013  Aug 08, 2014
Printed
Page 233
Index/F/functions

Book-defined functions:

I find it very helpful that also the book-defined functions made it into the index. (I find myself often looking for the definition of a function). There are a few omissions, though, like

flat p.124
pipeline p.177

What could even improve the experience would be if the function names stood out more against normal text key words. A simple typographic convention to achieve that would be to replace the word "function" with parentheses "()", e.g.

reduce (), 34

(The Underscore functions which are listed have the advantage of the "_." prefix in this respect). Alternatively, a constant width font for the function names could achieve a similar effect.

Speaking of typography it could also enhance the code samples in the text themselves. E.g. putting the name of functions in bold in their definition would be a great help.

ThomasH  Aug 17, 2013  Aug 08, 2014
Printed
Page 233
Index/F/functions

Here is a more complete list of book-defined functions missing from the index:

actions, 184
cat, 39
construct, 39
curry, 95
curry2, 96
curry3, 98
doWhen, 20
fail, 9
flat, 124
note, 9
nth, 12
pipeline, 177
second, 13
splat, 2
unsplat, 2
warn, 9

Note from the Author or Editor:
Thank you. Adding all of these would be nice.

ThomasH  Sep 05, 2013  Aug 08, 2014
Mobi
Page 9026
Ch8, location 9026

ACTUAL TEXT:
"However, there is one limitation of _chain ? it's not lazy."

EXPECTED TEXT:
"However, there is one limitation of _.chain ? it's not lazy."

NOTE:
The difference in `_chain` vs `_.chain`

Note from the Author or Editor:
Change to _.chain

ToddDitchendorf  Jan 17, 2014  Aug 08, 2014