Skip to content

Commit 09f021a

Browse files
committed
Add internal links
Plus a script that checks them for consistency
1 parent 1ed79b3 commit 09f021a

26 files changed

Lines changed: 509 additions & 338 deletions

00_intro.txt

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -268,9 +268,9 @@ console.log(sum(range(1, 10)));
268268
The moral of this story, then, is that the same program can be
269269
expressed in long and short, unreadable and readable ways. The first
270270
version of the program was extremely obscure, while this last one is
271-
almost English: `log` the `sum` of the `range` of numbers from 1
272-
to 10. (We will see in later chapters how to build things like `sum`
273-
and `range`.)
271+
almost English: `log` the `sum` of the `range` of numbers from 1 to
272+
10. (We will see in link:04_data.html#data[later chapters] how to
273+
build things like `sum` and `range`.)
274274

275275
(((programming language,power of)))A good programming language helps
276276
the programmer by allowing them to talk about the actions that the
@@ -345,7 +345,7 @@ to press)
345345
which JavaScript is used. Some databases, such as MongoDB and CouchDB,
346346
use JavaScript as their scripting and query language. Several
347347
platforms for desktop and server programming, most notably the
348-
_((Node.js))_ project, the subject of Chapter 20, are providing a
348+
_((Node.js))_ project, the subject of link:20_node.html#node[Chapter 20], are providing a
349349
powerful environment for programming JavaScript outside of the
350350
browser.
351351

@@ -375,9 +375,10 @@ endif::html_target[]
375375
ifdef::tex_target[]
376376

377377
Most of the example code in this book can be found on the book's
378-
website, at `eloquentjavascript.net/code`, which also provides
379-
an easy way to run the programs and experiment with writing your own
380-
code.
378+
website, at
379+
http://eloquentjavascript.net/code[_eloquentjavascript.net/code_],
380+
which also provides an easy way to run the programs and experiment
381+
with writing your own code.
381382

382383
endif::tex_target[]
383384

@@ -386,7 +387,7 @@ book's sandbox is also possible. You can opt to install Node.js, and
386387
read enough of its documentation to figure out how to use it to
387388
evaluate text files that contain programs. Or you can use your
388389
browser's developer console (typically found somewhere under a “tools”
389-
or “developer” menu) and play around in there. In Chapter 12, the
390+
or “developer” menu) and play around in there. In link:12_browser.html#script_tag[Chapter 12], the
390391
way in which JavaScript programs are embedded in web pages (HTML
391392
files) is explained. In the meantime, you could head over to
392393
_http://jsbin.com_ for another friendly interface for running

01_values.txt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
:prev_link: 00_intro
33
:next_link: 02_program_structure
44

5+
[[values]]
56
= Values, Types, and Operators =
67

78
[quote, Master Yuan-Ma, The Book of Programming]
@@ -268,7 +269,7 @@ The following line will produce the string `"concatenate"`:
268269
----
269270

270271
There are more ways of manipulating strings, which we will discuss
271-
when we get to methods in Chapter 4.
272+
when we get to methods in link:04_data.html#methods[Chapter 4].
272273

273274
== Unary operators ==
274275

@@ -285,6 +286,7 @@ console.log(typeof "x")
285286
// → string
286287
----
287288

289+
[[console.log]]
288290
We will use `console.log` in example code to indicate that we want to
289291
see the result of evaluating something. When you run such code, the
290292
value produced should be shown on the screen, though how it appears will
@@ -446,7 +448,7 @@ value. They are themselves values, but they carry no
446448
information.
447449

448450
Many operations in the language that don't produce a meaningful value
449-
(you'll see some in the next chapter) will yield `undefined` simply
451+
(you'll see some link:01_values.html#console.log[later]) will yield `undefined` simply
450452
because they have to yield _some_ value.
451453

452454
The difference in meaning between `undefined` and `null` is an accident
@@ -584,5 +586,5 @@ as several unary operators (`-` to negate a number, `!` to negate
584586
logically, and `typeof` to find a value's type).
585587

586588
This gives you enough information to use JavaScript as a pocket
587-
calculator, but not much more. The next chapter will start tying these
589+
calculator, but not much more. The link:02_program_structure.html#program_structure[next chapter] will start tying these
588590
basic expressions together into basic programs.

02_program_structure.txt

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
:prev_link: 01_values
33
:next_link: 03_functions
44

5+
[[program_structure]]
56
= Program Structure =
67

78
[chapterquote="true"]
@@ -20,7 +21,7 @@ to the point where we can actually express some meaningful prose.
2021

2122
== Expressions and statements ==
2223

23-
(((grammar)))(((JavaScript,syntax)))In Chapter 1, we made
24+
(((grammar)))(((JavaScript,syntax)))In link:01_values.html#values[Chapter 1], we made
2425
some values and then applied operators to them to get new values.
2526
Creating values like this is an essential part of every JavaScript
2627
program, but it is still only a part.
@@ -262,8 +263,9 @@ Though variable names cannot contain dots,
262263
`console.log` clearly has one. This is because `console.log` isn't
263264
a simple variable. It is actually an expression that
264265
retrieves the `log` field from the value held by the `console`
265-
variable. We will find out exactly what this means in Chapter 4.
266+
variable. We will find out exactly what this means in link:04_data.html#properties[Chapter 4].
266267

268+
[[return_values]]
267269
== Return values ==
268270

269271
(((side effect)))(((return value)))(((max function)))Showing a dialog
@@ -292,7 +294,8 @@ console.log(Math.min(2, 4) + 100);
292294
// → 102
293295
----
294296

295-
The next chapter explains how we can write our own functions.
297+
The link:03_functions.html#functions[next chapter] explains how we can
298+
write our own functions.
296299

297300
== prompt and confirm ==
298301

@@ -429,6 +432,7 @@ The flow chart for this program looks something like this:
429432

430433
image::img/controlflow-nested-if.svg[alt="Nested if control flow",width="4cm"]
431434

435+
[[loops]]
432436
== while and do loops ==
433437

434438
(((looping)))Consider a program that prints all even numbers from
@@ -575,9 +579,10 @@ for (var number = 0; number <= 12; number = number + 2)
575579
----
576580

577581
(((for loop)))(((control flow)))(((state)))This program is exactly
578-
equivalent to the earlier even-number-printing example. The only
579-
change is that all the statements that are related to the “state” of
580-
the loop are now on one line.
582+
equivalent to the link:02_program_structure.html#loops[earlier]
583+
even-number-printing example. The only change is that all the
584+
statements that are related to the “state” of the loop are now on one
585+
line.
581586

582587
The parentheses after a `for` keyword must contain two
583588
semicolons. The part before the first semicolon _initializes_ the
@@ -754,7 +759,7 @@ follow this convention.
754759
(((Number function)))(((constructor)))In a few cases, such as the
755760
`Number` function, the first letter of a variable is also capitalized.
756761
This was done to mark this function as a constructor. What a
757-
constructor is will become clear in Chapter 6. For now, the important
762+
constructor is will become clear in link:06_object.html#constructors[Chapter 6]. For now, the important
758763
thing is not to be bothered by this apparent lack of consistency.
759764

760765
== Comments ==
@@ -828,12 +833,13 @@ If you are unsure how to try your solutions to exercises, refer
828833
to the end of the introduction.
829834

830835
Each exercise starts with a problem description. Read that and try to
831-
solve the exercise. If you run into problems, consider reading
832-
the hints after the exercise. Full solutions to the exercises are not
833-
included in this book, but you can find them online at _http://eloquentjavascript.net/exercises.html_. If
834-
you want to learn, I recommend looking at these only after
835-
you've solved the exercise, or at least after you've attacked it long and hard
836-
enough to have a slight headache.
836+
solve the exercise. If you run into problems, consider reading the
837+
hints after the exercise. Full solutions to the exercises are not
838+
included in this book, but you can find them online at
839+
http://eloquentjavascript.net/exercises.html[_eloquentjavascript.net/exercises.html_].
840+
If you want to learn, I recommend looking at these only after you've
841+
solved the exercise, or at least after you've attacked it long and
842+
hard enough to have a slight headache.
837843

838844
=== Looping a triangle ===
839845

@@ -862,8 +868,8 @@ endif::html_target[]
862868

863869
You can start with a program that simply prints out the numbers 1 to
864870
7, which you can derive by making a few modifications to the
865-
even-number-printing example given earlier in the chapter, when the
866-
`for` loop was introduced.
871+
link:02_program_structure.html#loops[even-number-printing example]
872+
given earlier in the chapter, when the `for` loop was introduced.
867873

868874
Now consider the equivalence between numbers and strings of hash
869875
characters. You can go from 1 to 2 by adding 1 (`+= 1`). You can go

03_functions.txt

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
:prev_link: 02_program_structure
33
:next_link: 04_data
44

5+
[[functions]]
56
= Functions =
67

78
[chapterquote="true"]
@@ -145,6 +146,7 @@ function-local variables as existing only within the function, the
145146
language makes it possible to read and understand functions as small
146147
universes, without having to worry about all the code at once.
147148

149+
[[scoping]]
148150
== Nested scope ==
149151

150152
(((variable,scope)))(((inner function)))(((nested functions)))
@@ -248,7 +250,7 @@ if (safeMode)
248250
launchMissiles = function(value) {/* do nothing */};
249251
----
250252

251-
In Chapter 5, we will discuss the wonderful things that can be done by
253+
In link:05_higher_order.html#higher_order[Chapter 5], we will discuss the wonderful things that can be done by
252254
passing around function values to other functions.
253255

254256
== Declaration notation ==
@@ -302,6 +304,7 @@ function example() {
302304
}
303305
----
304306

307+
[[stack]]
305308
== The call stack ==
306309

307310
indexsee:[stack,call stack]
@@ -397,6 +400,7 @@ one will tell you about it.
397400

398401
indexsee:[optional argument,argument optional]
399402

403+
[[power]]
400404
(((argument,optional)))The upside is that this behavior can be used
401405
to have a function take “optional” arguments. For example, the
402406
following version of `power` can be called either with two arguments
@@ -422,7 +426,7 @@ console.log(power(4, 3));
422426
// → 64
423427
----
424428

425-
In the next chapter, we will see a way in which a function body can
429+
In the link:04_data.html#arguments_object[next chapter], we will see a way in which a function body can
426430
get at the exact list of arguments that were passed. This is helpful
427431
because it makes it possible for a function to accept any number of
428432
arguments. `console.log` makes use of this—it outputs all of the
@@ -546,12 +550,12 @@ between human-friendliness and machine-friendliness. Almost
546550
any program can be made faster by making it
547551
bigger and more convoluted. The programmer may decide on an appropriate balance.
548552

549-
In the case of the earlier `power` function, the inelegant (looping)
550-
version is still fairly simple and easy to read. It doesn't make much
551-
sense to replace it with the recursive version. Often, though, a
552-
program deals with such complex concepts that giving up some
553-
efficiency in order to make the program more straightforward becomes
554-
an attractive choice.
553+
In the case of the link:03_functions.html#power[earlier] `power`
554+
function, the inelegant (looping) version is still fairly simple and
555+
easy to read. It doesn't make much sense to replace it with the
556+
recursive version. Often, though, a program deals with such complex
557+
concepts that giving up some efficiency in order to make the program
558+
more straightforward becomes an attractive choice.
555559

556560
The basic rule, which has been repeated by many programmers and with
557561
which I wholeheartedly agree, is to not worry about efficiency until
@@ -578,6 +582,7 @@ with loops. Most often these are problems that require exploring or
578582
processing several “branches”, each of which might branch out again
579583
into more branches.
580584

585+
[[recursive_puzzle]]
581586
Consider this puzzle: by starting from the number 1 and repeatedly
582587
either adding 5 or multiplying by 3, an infinite amount of new
583588
numbers can be produced. How would you write a function that, given a
@@ -788,6 +793,7 @@ sure you're going to need it. It can be tempting to write general
788793
Resist that urge. You won't get any real work done, and you'll end up
789794
writing a lot of code that no one will ever use.
790795

796+
[[pure]]
791797
== Functions and side effects ==
792798

793799
(((side effect)))(((pure function)))(((function,purity)))Functions
@@ -860,9 +866,10 @@ sections help organize regular text.
860866

861867
=== Minimum ===
862868

863-
The previous chapter introduced the standard function `Math.min` that
864-
returns its smallest argument. We can do that ourselves now. Write a
865-
function `min` that takes two arguments and returns their minimum.
869+
The link:02_program_structure.html#return_values[previous chapter]
870+
introduced the standard function `Math.min` that returns its smallest
871+
argument. We can do that ourselves now. Write a function `min` that
872+
takes two arguments and returns their minimum.
866873

867874
ifdef::html_target[]
868875

@@ -928,13 +935,13 @@ endif::html_target[]
928935

929936
!!solution!!
930937

931-
Your function will likely look somewhat similar to the inner `find` function in
932-
the recursive `findSolution` example in this chapter, with an
933-
`if`/`else if`/`else` chain that tests which of the three cases
938+
Your function will likely look somewhat similar to the inner `find`
939+
function in the recursive `findSolution` link:03_functions.html#recursive_puzzle[example] in this chapter, with
940+
an `if`/`else if`/`else` chain that tests which of the three cases
934941
applies. The final `else`, corresponding to the third case, makes the
935-
recursive call. Each of the
936-
branches should contain a `return` statement or in some other way
937-
arrange for a specific value to be returned.
942+
recursive call. Each of the branches should contain a `return`
943+
statement or in some other way arrange for a specific value to be
944+
returned.
938945

939946
When given a negative number, the function will recurse again and
940947
again, passing itself an ever more negative number, thus getting

0 commit comments

Comments
 (0)