From 97635e6cad14dc37eb54208448f73ec1c1fea90a Mon Sep 17 00:00:00 2001
From: fenekku
Date: Fri, 11 May 2018 10:30:23 -0400
Subject: [PATCH 001/368] Link to Chapter 7 programming environment
While trying to make sure I didn't break anything in the pdf,
I realized I wasn't able to build it. So I fixed the needed
packages, but there seems to be a missing file (book.idx I
think?) that still prevents `make book.pdf` from running
properly.
---
07_robot.md | 7 ++++---
README.md | 2 +-
2 files changed, 5 insertions(+), 4 deletions(-)
diff --git a/07_robot.md b/07_robot.md
index 75578d45b..076415982 100644
--- a/07_robot.md
+++ b/07_robot.md
@@ -347,9 +347,10 @@ isn't planning ahead very well. We'll address that soon.
{{if interactive
For a more pleasant perspective on the simulation, you can use the
-`runRobotAnimation` function that's available in this chapter's
-programming environment. This runs the simulation, but instead of
-outputting text, it shows you the robot moving around the village map.
+`runRobotAnimation` function that's available in [this chapter's
+programming environment](https://eloquentjavascript.net/code/#7).
+This runs the simulation, but instead of outputting text, it shows
+you the robot moving around the village map.
```{test: no}
runRobotAnimation(VillageState.random(), randomRobot);
diff --git a/README.md b/README.md
index d3708def0..32d8a8c38 100644
--- a/README.md
+++ b/README.md
@@ -12,5 +12,5 @@ Feedback welcome, in the form of issues and pull requests.
To build the PDF file:
- apt-get install texlive texlive-xetex fonts-inconsolata fonts-symbola texlive-fonts-chinese
+ apt-get install texlive texlive-xetex fonts-inconsolata fonts-symbola texlive-lang-chinese inkscape
make book.pdf
From 1d0389cafaa00e33a0592ec80cfb113911e15942 Mon Sep 17 00:00:00 2001
From: Marijn Haverbeke
Date: Sat, 12 May 2018 23:22:12 +0200
Subject: [PATCH 002/368] Don't pre-load code that adds 'peanut teeth' event in
Chapter 4
---
04_data.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/04_data.md b/04_data.md
index 2f32e9fd8..0191aaaa1 100644
--- a/04_data.md
+++ b/04_data.md
@@ -799,7 +799,7 @@ a significant negative effect.
Interesting. Let's try something.
-```{includeCode: strip_log}
+```
for (let entry of JOURNAL) {
if (entry.events.includes("peanuts") &&
!entry.events.includes("brushed teeth")) {
From ad92d27e96d944da40630b00d2aecfce6905255c Mon Sep 17 00:00:00 2001
From: Marijn Haverbeke
Date: Tue, 15 May 2018 09:07:39 +0200
Subject: [PATCH 003/368] Integrate editing for Chapter 17
---
17_canvas.md | 46 +++++++++++++++++++++++-----------------------
1 file changed, 23 insertions(+), 23 deletions(-)
diff --git a/17_canvas.md b/17_canvas.md
index e84109f40..053af26a2 100644
--- a/17_canvas.md
+++ b/17_canvas.md
@@ -435,7 +435,7 @@ if}}
{{index "pie chart example"}}
Imagine you've just taken a ((job)) at EconomiCorp, Inc., and your
-first assignment is to draw a pie chart of their customer satisfaction
+first assignment is to draw a pie chart of its customer satisfaction
((survey)) results.
The `results` binding contains an array of objects that represent the
@@ -630,7 +630,7 @@ up an interval (repeated timer) to draw the next ((frame)):
{{index "remainder operator", "% operator"}}
-The `cycle` binding tracks our position in the ((animation)). Each
+The `cycle` binding tracks our position in the ((animation)). For each
((frame)), it is incremented and then clipped back to the 0 to 7 range
by using the remainder operator. This binding is then used to compute
the x-coordinate that the sprite for the current pose has in the
@@ -686,7 +686,7 @@ be position -100.
{{index "drawImage method"}}
So to turn a picture around, we can't simply add `cx.scale(-1, 1)`
-before the call to `drawImage` since that would move our picture
+before the call to `drawImage` because that would move our picture
outside of the ((canvas)), where it won't be visible. You could adjust
the ((coordinates)) given to `drawImage` to compensate for this by
drawing the image at x position -50 instead of 0. Another solution,
@@ -782,10 +782,10 @@ It is possible to save the current transformation, do some drawing and
transforming, and then restore the old transformation. This is usually
the proper thing to do for a function that needs to temporarily
transform the coordinate system. First, we save whatever
-transformation the code that called the function was using. Then, the
+transformation the code that called the function was using. Then the
function does its thing (on top of the existing transformation),
possibly adding more transformations. And finally, we revert to the
-transformation that we started with.
+transformation we started with.
{{index "save method", "restore method"}}
@@ -801,7 +801,7 @@ transformation.
The `branch` function in the following example illustrates what you
can do with a function that changes the transformation and then calls
-another function (in this case itself), which continues drawing with
+a function (in this case itself), which continues drawing with
the given transformation.
This function draws a treelike shape by drawing a line, moving the
@@ -899,7 +899,7 @@ class CanvasDisplay {
}
```
-The `setState` method first computes a new viewport, and then draws
+The `setState` method first computes a new viewport and then draws
the game scene at the appropriate position.
```{sandbox: "game", includeCode: true}
@@ -915,7 +915,7 @@ CanvasDisplay.prototype.setState = function(state) {
Contrary to `DOMDisplay`, this display style _does_ have to redraw the
background on every update. Because shapes on a canvas are just
-((pixel))s, after we draw them, there is no good way to move them (or
+((pixel))s, after we draw them there is no good way to move them (or
remove them). The only way to update the canvas display is to clear it
and redraw the scene. We may also have scrolled, which requires the
background to be in a different position.
@@ -952,8 +952,8 @@ CanvasDisplay.prototype.updateViewport = function(state) {
The calls to `Math.max` and `Math.min` ensure that the viewport does
not end up showing space outside of the level. `Math.max(x, 0)` makes
-sure the resulting number is not less than zero. `Math.min`,
-similarly, guarantees that a value stays below a given bound.
+sure the resulting number is not less than zero. `Math.min`
+similarly guarantees that a value stays below a given bound.
When ((clearing)) the display, we'll use a slightly different
((color)) depending on whether the game is won (brighter) or lost
@@ -1158,8 +1158,8 @@ blocks of text.
{{index zooming, SVG}}
SVG can be used to produce ((crisp)) ((graphics)) that look good at
-any zoom level. Contrary to HTML, it is actually designed for drawing,
-and thus more suitable for that purpose.
+any zoom level. Unlike HTML, it is designed for drawing
+and is thus more suitable for that purpose.
{{index DOM, SVG, "event handling"}}
@@ -1182,7 +1182,7 @@ pixel surface gives canvas a lower cost per shape.
{{index "ray tracer"}}
There are also effects, such as rendering a scene one pixel at a time
-(for example using a ray tracer) or postprocessing an image with
+(for example, using a ray tracer) or postprocessing an image with
JavaScript (blurring or distorting it), that can be realistically
handled only by a ((pixel))-based approach.
@@ -1341,11 +1341,11 @@ hint}}
[Earlier](canvas#pie_chart) in the chapter, we saw an example program
that drew a pie chart. Modify this program so that the name of each
category is shown next to the slice that represents it. Try to find a
-pleasing-looking way to automatically position this text, which would
+pleasing-looking way to automatically position this text that would
work for other data sets as well. You may assume that categories are
big enough to leave ample room for their labels.
-You might again need `Math.sin` and `Math.cos`, as described in
+You might need `Math.sin` and `Math.cos` again, which are described in
[Chapter ?](dom#sin_cos).
{{if interactive
@@ -1390,7 +1390,7 @@ but rather move the text out to the side of the pie by a given number
of pixels.
The ((angle)) of this line is `currentAngle + 0.5 * sliceAngle`. The
-following code finds a position on this line, 120 pixels from the
+following code finds a position on this line 120 pixels from the
center:
```{test: no}
@@ -1400,9 +1400,9 @@ let textY = Math.sin(middleAngle) * 120 + centerY;
```
For `textBaseline`, the value `"middle"` is probably appropriate when
-using this approach. What to use for `textAlign` depends on the side
+using this approach. What to use for `textAlign` depends on which side
of the circle we are on. On the left, it should be `"right"`, and on
-the right, it should be `"left"` so that the text is positioned away
+the right, it should be `"left"`, so that the text is positioned away
from the pie.
{{index "Math.cos function"}}
@@ -1464,8 +1464,8 @@ whole circle. Then fill the path.
To model the ball's position and ((speed)), you can use the `Vec`
class from [Chapter ?](game#vector)[ (which is available on this
page)]{if interactive}. Give it a starting speed, preferably one that
-is not purely vertical or horizontal, and every ((frame)), multiply
-that speed with the amount of time that elapsed. When the ball gets
+is not purely vertical or horizontal, and for every ((frame)) multiply
+that speed by the amount of time that elapsed. When the ball gets
too close to a vertical wall, invert the x component in its speed.
Likewise, invert the y component when it hits a horizontal wall.
@@ -1481,9 +1481,9 @@ hint}}
{{index optimization, "bitmap graphics", mirror}}
One unfortunate thing about ((transformation))s is that they slow down
-drawing of bitmaps. The position and size of each ((pixel)) has to be
-transformed, and though it is possible that ((browser))s will get more
-clever about this in the ((future)), this currently causes a
+the drawing of bitmaps. The position and size of each ((pixel)) has to be
+transformed, and though it is possible that ((browser))s will get
+cleverer about transformation in the ((future)), they currently cause a
measurable increase in the time it takes to draw a bitmap.
In a game like ours, where we are drawing only a single transformed
From e232dd328a5491acfcb7750624e41c2c08bdbe4f Mon Sep 17 00:00:00 2001
From: Marijn Haverbeke
Date: Tue, 15 May 2018 09:13:56 +0200
Subject: [PATCH 004/368] Integrate tech editing for Chapter 12
---
code/solutions/12_1_arrays.js | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/code/solutions/12_1_arrays.js b/code/solutions/12_1_arrays.js
index f31d7bcd8..e857c914b 100644
--- a/code/solutions/12_1_arrays.js
+++ b/code/solutions/12_1_arrays.js
@@ -1,8 +1,8 @@
-topEnv.array = (...values) => values;
+topScope.array = (...values) => values;
-topEnv.length = array => array.length;
+topScope.length = array => array.length;
-topEnv.element = (array, i) => array[i];
+topScope.element = (array, i) => array[i];
run(`
do(define(sum, fun(array,
From 91508db3dc5be56357e91e083be98ba735512671 Mon Sep 17 00:00:00 2001
From: Marijn Haverbeke
Date: Wed, 16 May 2018 08:46:29 +0200
Subject: [PATCH 005/368] Link to Amazon pre-order page for 3rd edition
---
html/index.html | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/html/index.html b/html/index.html
index 4993bed06..b617abb33 100644
--- a/html/index.html
+++ b/html/index.html
@@ -25,8 +25,8 @@ Eloquent JavaScript
3rd edition
This is a book about JavaScript, programming, and the wonders of
the digital. You can read it online here, or get your own
paperback
- copy of the second edition. A paper third edition is
- being worked on, but it isn't clear yet when it'll be available.
+ copy of the second edition. A paper third edition is expected to be available this October.
+ .
From c1ad6ae5709d31895e9ea738bc20c31ca6c08d07 Mon Sep 17 00:00:00 2001
From: Marijn Haverbeke
Date: Thu, 17 May 2018 10:21:29 +0200
Subject: [PATCH 006/368] Integrate editing for Chapter 18
---
09_regexp.md | 6 ++---
18_http.md | 56 +++++++++++++++++++++++-----------------------
21_skillsharing.md | 2 +-
3 files changed, 32 insertions(+), 32 deletions(-)
diff --git a/09_regexp.md b/09_regexp.md
index 408ad0ff8..fdb139cad 100644
--- a/09_regexp.md
+++ b/09_regexp.md
@@ -836,7 +836,7 @@ When creating the `\b` ((boundary)) markers, we have to use two
backslashes because we are writing them in a normal string, not a
slash-enclosed regular expression. The second argument to the `RegExp`
constructor contains the options for the regular expression—in this
-case, `"gi"` for global and case-insensitive.
+case, `"gi"` for global and case insensitive.
But what if the name is `"dea+hl[]rd"` because our user is a ((nerd))y
teenager? That would result in a nonsensical regular expression that
@@ -1223,7 +1223,7 @@ starting position of the match. Their `replace` method can replace
matches of a pattern with a replacement string or function.
Regular expressions can have options, which are written after the
-closing slash. The `i` option makes the match case-insensitive. The
+closing slash. The `i` option makes the match case insensitive. The
`g` option makes the expression _global_, which, among other things,
causes the `replace` method to replace all instances instead of just
the first. The `y` option makes it sticky, which means that it will
@@ -1421,7 +1421,7 @@ digits _or_ a dot followed by one or more digits.
{{index exponent, "case sensitivity", ["regular expression", flags]}}
-Finally, to make the _e_ case-insensitive, either add an `i` option to
+Finally, to make the _e_ case insensitive, either add an `i` option to
the regular expression or use `[eE]`.
hint}}
diff --git a/18_http.md b/18_http.md
index 231ef2972..e589a351c 100644
--- a/18_http.md
+++ b/18_http.md
@@ -74,7 +74,7 @@ it to `DELETE` its main page, it'll probably refuse.
{{index [path, URL], GitHub}}
-The part after the ((method)) name is the path of the ((resource)) the
+The part after the ((method)) name is the path of the _((resource))_ the
request applies to. In the simplest case, a resource is simply a
((file)) on the ((server)), but the protocol doesn't require it to be.
A resource may be anything that can be transferred _as if_ it is a
@@ -89,7 +89,7 @@ After the resource path, the first line of the request mentions
is using.
In practice, many sites use HTTP version 2, which supports the same
-concepts as version 1.1, but is a lot more complicated so that it can
+concepts as version 1.1 but is a lot more complicated so that it can
be faster. Browsers will automatically switch to the appropriate
protocol version when talking to a given server, and the outcome of a
request is the same regardless which version is used. Because version
@@ -230,7 +230,7 @@ console.log(decodeURIComponent("Yes%3F"));
If we change the `method` attribute of the HTML form in the example we
saw earlier to `POST`, the ((HTTP)) request made to submit the
((form)) will use the `POST` method and put the ((query string)) in
-body of the request, rather than adding it to the URL.
+the body of the request, rather than adding it to the URL.
```{lang: http}
POST /example/message.html HTTP/1.1
@@ -275,21 +275,21 @@ fetch("example/data.txt").then(response => {
Calling `fetch` returns a promise that resolves to a `Response` object
holding information about the server's response, such as its status
code and its headers. The headers are wrapped in a `Map`-like object
-that treats its keys (the header names) as case-insensitive, because
+that treats its keys (the header names) as case insensitive, because
header names are not supposed to be case sensitive. This means that
`headers.get("Content-Type")` and `headers.get("content-TYPE")` will
return the same value.
Note that the promise returned by `fetch` resolves successfully even
if the server responded with an error code. It _might_ also be
-rejected, if there is a network error or the ((server)) that the
+rejected, if there is a network error or if the ((server)) that the
request is addressed to can't be found.
{{index [path, URL], "relative URL"}}
The first argument to `fetch` is the URL that should be requested.
When that ((URL)) doesn't start with a protocol name (such as _http:_)
-it is treated as relative, which means that it is interpreted relative
+it is treated as _relative_, which means it is interpreted relative
to the current document. When it starts with a slash (/), it replaces
the current path, which is the part after the server name. When it
does not, the part of the current path up to and including its last
@@ -317,7 +317,7 @@ rejects if it's not valid JSON.
{{index "GET method", "body (HTTP)", "DELETE method", "method property"}}
-By default, `fetch` uses the `GET` method to make its request, and
+By default, `fetch` uses the `GET` method to make its request and
does not include a request body. You can configure it differently by
passing an object with extra options as a second argument. For
example, this request tries to delete `example/data.txt`.
@@ -374,7 +374,7 @@ _mybank.com_).
{{index "Access-Control-Allow-Origin header", "cross-domain request"}}
-This can be an annoying problem when building systems that wants to
+This can be an annoying problem when building systems that want to
access several domains for legitimate reasons. Fortunately,
((server))s can include a ((header)) like this in their ((response))
to explicitly indicate to the browser that it is okay for the request
@@ -430,7 +430,7 @@ server interface around.
Data traveling over the Internet tends to follow a long, dangerous
road. To get to its destination, it must hop through anything from
-coffee-shop Wi-Fi to ((network))s controlled by various companies and
+coffee-shop Wi-Fi hotspots to ((network))s controlled by various companies and
states. At any point along its route it may be inspected or even
modified.
@@ -445,16 +445,16 @@ to via your bank's website, plain HTTP is not good enough.
{{indexsee "Secure HTTP", HTTPS}}
-The secure ((HTTP)) protocol, whose ((URL))s start with _https://_,
+The secure ((HTTP)) protocol, used for ((URL))s start with _https://_,
wraps HTTP traffic in a way that makes it harder to read and tamper
with. Before exchanging data, the client verifies that the server is
-who it claims to be, by asking it to prove that it has a cryptographic
+who it claims to be by asking it to prove that it has a cryptographic
((certificate)) issued by a certificate authority that the ((browser))
recognizes. Next, all data going over the ((connection)) is encrypted
in a way that should prevent eavesdropping and tampering.
-Thus, when it works right, ((HTTPS)) prevents both the someone
-impersonating the website you were trying to talk to and the someone
+Thus, when it works right, ((HTTPS)) prevents other people from
+impersonating the website you are trying to talk to and from
snooping on your communication. It is not perfect, and there have been
various incidents where HTTPS failed because of forged or stolen
certificates and broken software, but it is a _lot_ safer than plain
@@ -564,7 +564,7 @@ predefined options.
Such a field looks like this:
-{{figure {url: "img/form_select.png", alt: "A select field",width: "4cm"}}}
+{{figure {url: "img/form_select.png", alt: "A select field", width: "4cm"}}}
if}}
@@ -636,7 +636,7 @@ the OK button, rather than going through the help link first:
{{index "tabindex attribute"}}
By default, most types of HTML elements cannot be focused. But you can
-add a `tabindex` attribute to any element, which will make it
+add a `tabindex` attribute to any element that will make it
focusable. A `tabindex` of -1 makes tabbing skip over an element, even
if it is normally focusable.
@@ -665,8 +665,8 @@ if}}
{{index "user experience", "asynchronous programming"}}
When a program is
-in the process of handling an action caused by some ((button)) or other control,
-which might require communication with the server and thus take a
+in the process of handling an action caused by some ((button)) or other control
+that might require communication with the server and thus take a
while, it can be a good idea to
disable the control until the action finishes. That way, when the user
gets impatient and clicks it again, they don't accidentally repeat
@@ -1104,7 +1104,7 @@ prevents the feature from eating up too much space.
{{index "localStorage object", "note-taking example", "select (HTML tag)", "button (HTML tag)", "textarea (HTML tag)"}}
The following code implements a crude note-taking application. It
-keeps a set of named notes, and allows the user to edit notes and
+keeps a set of named notes and allows the user to edit notes and
create new ones.
```{lang: "text/html", startCode: true}
@@ -1165,7 +1165,7 @@ exist from `localStorage` will yield `null`. Passing `null` to
Thus, the `||` operator can be used to provide a default value in a
situation like this.
-The `setState` method makes sure the DOM is showing a given state, and
+The `setState` method makes sure the DOM is showing a given state and
stores the new state to `localStorage`. Event handlers call this
function to move to a new state.
@@ -1173,11 +1173,11 @@ function to move to a new state.
The use of `Object.assign` in the example is intended to create a new
object that is a clone of the old `state.notes`, but with one property
-added or overwritten. `Object.assign` takes its first argument, and
+added or overwritten. `Object.assign` takes its first argument and
adds all properties from any further arguments to it. Thus, giving it
an empty object will cause it to fill a fresh object. The ((square
brackets)) notation in the third argument is used to create a property
-whose names is based on some dynamic value.
+whose name is based on some dynamic value.
{{index "sessionStorage object"}}
@@ -1229,7 +1229,7 @@ file picker field, the `FileReader` interface can be used to access
the content of this file from a JavaScript program.
The `localStorage` and `sessionStorage` objects can be used to save
-information in a way that survives page reloads. The first saves the
+information in a way that survives page reloads. The first object saves the
data forever (or until the user decides to clear it), and the second
saves it until the browser is closed.
@@ -1239,7 +1239,7 @@ saves it until the browser is closed.
{{index "Accept header", "media type", "document format", "content negotiation (exercise)"}}
-One of the things that HTTP can do is called _content negotiation_.
+One of the things HTTP can do is called _content negotiation_.
The `Accept` request header is used to tell the server what type of
document the client would like to get. Many servers ignore this
header, but when a server knows of various ways to encode a resource,
@@ -1295,7 +1295,7 @@ JavaScript code.
{{index "textarea (HTML tag)", "button (HTML tag)", "Function constructor", "error message"}}
-Put a button next to a `