Skip to content

Commit 2abdc04

Browse files
committed
Rewrite the code for Chapter 16
Less stateful, cleaner. Update relevant text.
1 parent 29ccb67 commit 2abdc04

File tree

6 files changed

+909
-1131
lines changed

6 files changed

+909
-1131
lines changed

04_data.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -406,12 +406,13 @@ one more piece of theory to understand.
406406

407407
We saw that object values can be modified. The types of values
408408
discussed in earlier chapters, such as numbers, strings, and Booleans,
409-
are all _immutable_—it is impossible to change an existing value of
410-
those types. You can combine them and derive new values from them, but
411-
when you take a specific string value, that value will always remain
412-
the same. The text inside it cannot be changed. If you have reference
413-
to a string that contains `"cat"`, it is not possible for other code
414-
to change a character in your string to make it spell `"rat"`.
409+
are all _((immutable))_—it is impossible to change an existing value
410+
of those types. You can combine them and derive new values from them,
411+
but when you take a specific string value, that value will always
412+
remain the same. The text inside it cannot be changed. If you have
413+
reference to a string that contains `"cat"`, it is not possible for
414+
other code to change a character in your string to make it spell
415+
`"rat"`.
415416

416417
With objects, on the other hand, the content of a value _can_ be
417418
modified by changing its properties.

06_object.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -996,15 +996,15 @@ existing class, _inheriting_ part of its behavior.
996996

997997
### A vector type
998998

999-
{{index dimensions, "Vector type", coordinates, "vector (exercise)"}}
999+
{{index dimensions, "Vec class", coordinates, "vector (exercise)"}}
10001000

1001-
Write a ((class)) `Vector` that represents a vector in two-dimensional
1001+
Write a ((class)) `Vec` that represents a vector in two-dimensional
10021002
space. It takes `x` and `y` parameters (numbers), which it should save
10031003
to properties of the same name.
10041004

10051005
{{index addition, subtraction}}
10061006

1007-
Give the `Vector` prototype two methods, `plus` and `minus`, that take
1007+
Give the `Vec` prototype two methods, `plus` and `minus`, that take
10081008
another vector as a parameter and return a new vector that has the sum
10091009
or difference of the two vectors’ (the one in `this` and the
10101010
parameter) _x_ and _y_ values.
@@ -1018,11 +1018,11 @@ the origin (0, 0).
10181018
```{test: no}
10191019
// Your code here.
10201020
1021-
console.log(new Vector(1, 2).plus(new Vector(2, 3)));
1022-
// → Vector{x: 3, y: 5}
1023-
console.log(new Vector(1, 2).minus(new Vector(2, 3)));
1024-
// → Vector{x: -1, y: -1}
1025-
console.log(new Vector(3, 4).length);
1021+
console.log(new Vec(1, 2).plus(new Vec(2, 3)));
1022+
// → Vec{x: 3, y: 5}
1023+
console.log(new Vec(1, 2).minus(new Vec(2, 3)));
1024+
// → Vec{x: -1, y: -1}
1025+
console.log(new Vec(3, 4).length);
10261026
// → 5
10271027
```
10281028
if}}

0 commit comments

Comments
 (0)