Skip to content

Commit a831715

Browse files
committed
Add index terms to Chapter 9
1 parent 9ecaee6 commit a831715

9 files changed

Lines changed: 662 additions & 582 deletions

00_intro.txt

Lines changed: 45 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,27 @@ appeal to our sense of the physical world, and build interfaces that
1818
mimic that world, and allow us to manipulate shapes on a screen with
1919
our fingers. This works very well for casual machine interaction.
2020

21-
(((programming language)))But we have not yet found a good way to use
22-
the point-and-click approach to communicate things to the computer
23-
that the designer of the interface did not anticipate. For open-ended
24-
interfaces, such as instructing the computer to perform arbitrary
25-
tasks, we've had more luck with an approach that makes use of our
26-
talent for language: teaching the machine a language.
27-
28-
(((human language)))Human languages allow words and subsentences to be
29-
combined in many, many ways, allowing us to say many, many different
30-
things. Computer languages, though typically less grammatically
31-
flexible, follow a similar principle.
32-
33-
(((JavaScript,availability of)))(((browser)))Casual computing has
34-
become become much more widespread in the past twenty years, and
21+
(((programming language)))(((machine language)))But we have not yet
22+
found a good way to use the point-and-click approach to communicate
23+
things to the computer that the designer of the interface did not
24+
anticipate. For open-ended interfaces, such as instructing the
25+
computer to perform arbitrary tasks, we've had more luck with an
26+
approach that makes use of our talent for language: teaching the
27+
machine a language.
28+
29+
(((human language)))(((expressivity)))Human languages allow words and
30+
subsentences to be combined in many, many ways, allowing us to say
31+
many, many different things. Computer languages, though typically less
32+
grammatically flexible, follow a similar principle.
33+
34+
(((JavaScript,availability of)))(((casual computing)))Casual computing
35+
has become become much more widespread in the past twenty years, and
3536
language-based interfaces, which once were the default way in which
3637
people interacted with computers, have largely been replaced with
3738
graphical interfaces. But they are still there, if you know where to
3839
look. One such language, _JavaScript_, is built into just about every
39-
web browser, and thus available on just about every consumer device.
40+
web ((browser)), and thus available on just about every consumer
41+
device.
4042

4143
indexsee:[web browser,browser]
4244

@@ -61,7 +63,7 @@ clear. But programs, built on top of these basic rules, tend to become
6163
complex enough to introduce their own rules and complexity. You're
6264
building your own maze, in a way, and might just get lost in it.
6365

64-
There will be times at which reading this book feels terribly
66+
(((learning)))There will be times at which reading this book feels terribly
6567
frustrating. If you are new to programming, there will be a lot of new
6668
material to digest. Much of this material will then be _combine_ in
6769
ways that require you to make additional connections.
@@ -117,16 +119,17 @@ strict rules (_“best practices”_) prescribing the form programs should
117119
have, and the more zealous among them will consider those that go
118120
outside of this little safe zone to be _bad_ programmers.
119121

120-
What hostility to the richness of programming—to try to reduce it to
121-
something straightforward and predictable, to place a taboo on all the
122-
weird and beautiful programs! The landscape of programming techniques
123-
is enormous, fascinating in its diversity, and still largely
124-
unexplored. It is certainly dangerous going, luring the inexperienced
125-
programmer into all kinds of confusion, but that only means you should
126-
proceed with caution and keep your wits about you. As you learn, there
127-
will always be new challenges and new territory to explore.
128-
Programmers who refuse to keep exploring will stagnate, forget their
129-
joy, and get bored with their craft.
122+
(((experiment)))(((learning)))What hostility to the richness of
123+
programming—to try to reduce it to something straightforward and
124+
predictable, to place a taboo on all the weird and beautiful programs!
125+
The landscape of programming techniques is enormous, fascinating in
126+
its diversity, and still largely unexplored. It is certainly dangerous
127+
going, luring the inexperienced programmer into all kinds of
128+
confusion, but that only means you should proceed with caution and
129+
keep your wits about you. As you learn, there will always be new
130+
challenges and new territory to explore. Programmers who refuse to
131+
keep exploring will stagnate, forget their joy, and get bored with
132+
their craft.
130133

131134
== Why language matters ==
132135

@@ -317,22 +320,23 @@ has its advantages, though. It leaves space for a lot of techniques
317320
that are impossible in more rigid languages, and, as we will see, for
318321
example, in the link:10_modules.html#modules[chapter on modules], it
319322
can be used to overcome some of JavaScript's shortcomings. After
320-
learning the language properly and working with it for a while, I have
323+
((learning)) the language properly and working with it for a while, I have
321324
learned to actually _like_ JavaScript.
322325

323-
(((JavaScript,versions of)))(((ECMAScript)))(((ECMAScript 6)))There
324-
have been several _versions_ of JavaScript. ECMAScript version 3 was
325-
the dominant, widely supported version in the time of JavaScript's
326-
ascent to dominance, roughly between 2000 and 2010. During this time,
327-
work was underway on an ambitious version 4, which planned a number of
328-
radical improvements and extensions to the language. Changing a
329-
living, widely used language in such a radical way turned out to be
330-
politically difficult, and work on the 4th edition was abandoned in
331-
2008, leading to the much less ambitious 5th edition coming out in
332-
2009. We're now at the point where all major browsers support this 5th
333-
edition, which is the language version that this book will be focusing
334-
on. A 6th edition is in the process of being finalized, and some
335-
browsers are starting to support new features from this edition.
326+
(((future)))(((JavaScript,versions of)))(((ECMAScript)))(((ECMAScript
327+
6)))There have been several _versions_ of JavaScript. ECMAScript
328+
version 3 was the dominant, widely supported version in the time of
329+
JavaScript's ascent to dominance, roughly between 2000 and 2010.
330+
During this time, work was underway on an ambitious version 4, which
331+
planned a number of radical improvements and extensions to the
332+
language. Changing a living, widely used language in such a radical
333+
way turned out to be politically difficult, and work on the 4th
334+
edition was abandoned in 2008, leading to the much less ambitious 5th
335+
edition coming out in 2009. We're now at the point where all major
336+
browsers support this 5th edition, which is the language version that
337+
this book will be focusing on. A 6th edition is in the process of
338+
being finalized, and some browsers are starting to support new
339+
features from this edition.
336340

337341
(((JavaScript,uses of)))Web browsers are not the only platforms on
338342
which JavaScript is used. Some databases, such as MongoDB and CouchDB,
@@ -347,7 +351,7 @@ outside of the browser.
347351
(((reading code)))(((writing code)))Code is the text that makes up
348352
programs. Most chapters in this book contain quite a lot of it. In my
349353
experience, reading and writing ((code)) is an indispensable part of
350-
learning to program. Try to not just glance over the examples, read
354+
((learning)) to program. Try to not just glance over the examples, read
351355
them attentively and understand them. This will be slow and confusing
352356
at first, but I promise that you will quickly get the hang of it. The
353357
same goes for the ((exercises)). Don't assume you understand them

01_values.txt

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,10 @@ dot.
122122
9.81
123123
----
124124

125-
(((scientific notation)))(((Number type,notation)))For very big or
126-
very small numbers, you can also use scientific notation by adding an
127-
“e”, followed by the exponent of the number:
125+
(((exponent)))(((scientific notation)))(((Number type,notation)))For
126+
very big or very small numbers, you can also use scientific notation
127+
by adding an “e” (for “exponent”), followed by the exponent of the
128+
number:
128129

129130
[source,javascript]
130131
----
@@ -157,26 +158,27 @@ number from them. Here is what they look like in JavaScript:
157158
100 + 4 * 11
158159
----
159160

160-
(((pass:[*] operator)))(((+ operator)))The `+` and `*` symbols are
161-
called _operators_. The first stands for addition, and the second
162-
stands for multiplication. Putting an operator between two values will
163-
(((application,of operators)))apply it to those values and produce a
164-
new value.
161+
(((asterisk)))(((plus character)))(((pass:[*] operator)))(((+
162+
operator)))The `+` and `*` symbols are called _operators_. The first
163+
stands for addition, and the second stands for multiplication. Putting
164+
an operator between two values will (((application,of
165+
operators)))apply it to those values and produce a new value.
165166

166-
(((parentheses)))(((precedence)))Does the example mean “add 4 and 100,
167-
and multiply the result by 11”, or is the multiplication done before
168-
the adding? As you might have guessed, the multiplication happens
169-
first. But, as in mathematics, you can change this by wrapping the
170-
addition in parentheses.
167+
(((grouping)))(((parentheses)))(((precedence)))Does the example mean
168+
“add 4 and 100, and multiply the result by 11”, or is the
169+
multiplication done before the adding? As you might have guessed, the
170+
multiplication happens first. But, as in mathematics, you can change
171+
this by wrapping the addition in parentheses.
171172

172173
[source,javascript]
173174
----
174175
(100 + 4) * 11
175176
----
176177

177-
(((division)))(((subtraction)))(((- operator)))(((/ operator)))For
178-
subtraction, there is the `-` operator, and division can be done with
179-
the `/` operator.
178+
(((dash character)))(((slash
179+
character)))(((division)))(((subtraction)))(((minus)))(((-
180+
operator)))(((/ operator)))For subtraction, there is the `-` operator,
181+
and division can be done with the `/` operator.
180182

181183
When operators appear together without parentheses, the order in which
182184
they are applied is determined by the _((precedence))_ of the
@@ -219,7 +221,8 @@ numeric operations that don't yield a precise, meaningful result.
219221
== Strings ==
220222

221223
(((syntax)))(((String type)))(((textual
222-
data)))(((character)))(((String type,notation)))(((quote)))The next
224+
data)))(((character)))(((String type,notation)))(((single-quote
225+
character)))(((double-quote character)))(((quotation mark)))The next
223226
basic data type is the _string_. Strings are used to represent text.
224227
They are written by enclosing their content in quotes.
225228

@@ -232,12 +235,12 @@ They are written by enclosing their content in quotes.
232235
Both single and double quotes can be used to mark strings as long as
233236
the quotes at the start and the end of the string match.
234237

235-
(((newline character)))Almost anything can be put between quotes, and
236-
JavaScript will make a string value out of it. But a few characters
237-
are more difficult. You can imagine how putting quotes between quotes
238-
might be hard. _Newlines_ (the characters you get when you press
239-
Enter) also can't be put between quotes. The string has to stay on a
240-
single line.
238+
(((line break)))(((newline character)))Almost anything can be put
239+
between quotes, and JavaScript will make a string value out of it. But
240+
a few characters are more difficult. You can imagine how putting
241+
quotes between quotes might be hard. _Newlines_ (the characters you
242+
get when you press Enter) also can't be put between quotes. The string
243+
has to stay on a single line.
241244

242245
(((escaping,in strings)))(((backslash)))To be able to have such
243246
characters in a string, the following notation is used: whenever a

02_program_structure.txt

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,12 @@ applied operators to them to get new values. Creating values like this
2727
is an essential part of every JavaScript program, but it is still only
2828
a part.
2929

30-
A fragment of code that produces a value is called an
31-
_((expression))_. Every value that is written literally (such as `22`
32-
or `"psychoanalysis"`) is an expression. An expression between
33-
((parentheses)) is also an expression, as is a ((binary operator))
34-
applied to two expressions or a unary operator applied to one.
30+
(((literal expression)))A fragment of code that produces a value is
31+
called an _((expression))_. Every value that is written literally
32+
(such as `22` or `"psychoanalysis"`) is an expression. An expression
33+
between ((parentheses)) is also an expression, as is a ((binary
34+
operator)) applied to two expressions or a unary operator applied to
35+
one.
3536

3637
(((nesting,of expressions)))(((human language)))This shows part of the
3738
beauty of a language-based interface. Expressions can nest in a way
@@ -68,7 +69,7 @@ happens.
6869
(((programming style)))(((automatic semicolon
6970
insertion)))(((semicolon)))In some cases, JavaScript allows you to
7071
omit the semicolon at the end of a statement. In other cases, it has
71-
to be there, the next line will be treated as part of the same
72+
to be there, the next ((line)) will be treated as part of the same
7273
statement. The rules for when it can be safely omitted are somewhat
7374
complex and error-prone. In this book, every statement that needs a
7475
semicolon will always be terminated by one. I recommend you do the
@@ -176,7 +177,7 @@ words)))(((static (reserved word))))(((void operator)))(((yield
176177
(reserved word))))(((reserved words)))(((variable,naming)))Words with
177178
a special meaning, such as `var`, are _((keyword))s_, and they may not
178179
be used as variable names. There are also a number of words that are
179-
“reserved for use” in future versions of JavaScript. These are also
180+
“reserved for use” in ((future)) versions of JavaScript. These are also
180181
officially not allowed to be used as variable names, though some
181182
JavaScript environments do allow them. The full list of keywords and
182183
reserved words is rather long.
@@ -494,10 +495,10 @@ keyword `while` creates a loop. The word `while` is followed by an
494495
The loop executes that statement as long as the expression produces a
495496
value that is `true` when converted to Boolean type.
496497

497-
((({} (block))))(((block)))In this loop, we want to both
498+
(((grouping)))((({} (block))))(((block)))In this loop, we want to both
498499
print the current number and add two to our variable. Whenever we need
499500
to execute multiple ((statement))s inside a loop, we wrap them in
500-
((braces)) (`{` and `}`). Braces do for statements what
501+
((curly braces)) (`{` and `}`). Braces do for statements what
501502
((parentheses)) do for expressions: they group them together, making
502503
them count as a single statement. A sequence of statements wrapped in
503504
braces is called a _block_.
@@ -564,7 +565,7 @@ except `""` convert to `true`.
564565
(((block)))(((code,structure of)))(((whitespace)))(((programming
565566
style)))You've probably noticed the spaces I put in front of some
566567
statements. In JavaScript, these are not required—the computer will
567-
accept the program just fine without them. In fact, even the line
568+
accept the program just fine without them. In fact, even the ((line))
568569
breaks in programs are optional. You could write a program as a single
569570
long line if you felt like it. The role of the ((indentation)) inside
570571
blocks is to make the structure of the code stand out. In complex
@@ -996,11 +997,11 @@ character is written `"\n"`.
996997
Use `console.log` to inspect the output of your program.
997998

998999
(((nesting,of loops)))To work with two ((dimensions)), you will need a
999-
((loop)) inside of a loop. Put ((braces)) around the bodies of both
1000-
loops to make it easy to see where they start and end. Try to properly
1001-
indent these bodies. The order of the loops must follow the order in
1002-
which we build up the string (line by line, left to right, top to
1003-
bottom). So the outer loop handles the lines and the inner loop
1000+
((loop)) inside of a loop. Put ((curly braces)) around the bodies of
1001+
both loops to make it easy to see where they start and end. Try to
1002+
properly indent these bodies. The order of the loops must follow the
1003+
order in which we build up the string (line by line, left to right,
1004+
top to bottom). So the outer loop handles the lines and the inner loop
10041005
handles the characters on a line.
10051006

10061007
(((counter variable)))(((remainder operation)))(((% operator)))You'll

03_functions.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -277,10 +277,10 @@ function square(x) {
277277
}
278278
----
279279

280-
(((execution order)))This is a function _declaration_. The statement
281-
defines the variable `square` and points it at the given function. So
282-
far so good. There is one subtlety with this form of function
283-
definition, however.
280+
(((future)))(((execution order)))This is a function _declaration_. The
281+
statement defines the variable `square` and points it at the given
282+
function. So far so good. There is one subtlety with this form of
283+
function definition, however.
284284

285285
[source,javascript]
286286
----

04_data.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,12 @@ expression that corresponds to the _((index))_ given by the expression
110110
in the brackets.
111111

112112
[[array_indexing]]
113-
(((zero-based counting)))The first index of an array is zero, not one.
114-
So the first element can be read with `listOfNumbers[0]`. If you don't
115-
have a programming background, this convention might take some getting
116-
used to. But zero-based counting has a long tradition in technology,
117-
and as long as this convention is followed consistently (which it is,
118-
in JavaScript), it works well.
113+
The first index of an array is zero, not one. So the first element can
114+
be read with `listOfNumbers[0]`. If you don't have a programming
115+
background, this convention might take some getting used to. But
116+
((zero-based counting)) has a long tradition in technology, and as
117+
long as this convention is followed consistently (which it is, in
118+
JavaScript), it works well.
119119

120120
[[properties]]
121121
== Properties ==

07_elife.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -391,12 +391,12 @@ inside the ((loop)). Instead, the outer function creates a normal
391391
local variable, `grid`, through which the inner function gets access
392392
to the grid.
393393

394-
(((ECMAScript 6)))(((arrow function)))(((self variable)))This is a bit
395-
of a design blunder in JavaScript. Fortunately, the next version of
396-
the language provides a solution for this problem. Meanwhile, there
397-
are workarounds. A common pattern is to say `var self = this` and from
398-
then on refer to `self`, which is a normal variable and thus visible
399-
to inner functions.
394+
(((future)))(((ECMAScript 6)))(((arrow function)))(((self
395+
variable)))This is a bit of a design blunder in JavaScript.
396+
Fortunately, the next version of the language provides a solution for
397+
this problem. Meanwhile, there are workarounds. A common pattern is to
398+
say `var self = this` and from then on refer to `self`, which is a
399+
normal variable and thus visible to inner functions.
400400

401401
(((bind method)))(((this)))Another solution is to use the `bind`
402402
method, which allows us to provide an explicit `this` object to bind

0 commit comments

Comments
 (0)