11:chap_num: 6
22:prev_link: 05_higher_order
33:next_link: 07_elife
4- :load_files: ["js/code/mountains.js", "js/code/ 06_object.js"]
4+ :load_files: ["js/code/mountains.js", "js/06_object.js"]
55
66= The Secret Life of Objects =
77
@@ -78,6 +78,8 @@ property and immediately called, as in ++object.method()++—the special
7878variable `this` in its body will point to the object that it was
7979called on.
8080
81+ // include_code top_lines:6
82+
8183[source,javascript]
8284----
8385function speak(line) {
@@ -213,6 +215,8 @@ Here is a simple constructor for rabbits. It is convention to
213215capitalize the names of constructors, so that they are easily
214216distinguished from other functions.
215217
218+ // include_code top_lines:6
219+
216220[source,javascript]
217221----
218222function Rabbit(type) {
@@ -231,6 +235,8 @@ New objects created with this constructor will get this object as
231235their prototype. So to add a `speak` method to rabbits created with
232236the `Rabbit` constructor, we can simply do this:
233237
238+ // include_code top_lines:4
239+
234240[source,javascript]
235241----
236242Rabbit.prototype.speak = function(line) {
@@ -318,6 +324,8 @@ associate values with names by creating properties for the names and
318324giving them the corresponding value as value. Here's a similar example
319325from chapter 4:
320326
327+ // include_code
328+
321329[source,javascript]
322330----
323331var ages = {};
@@ -503,6 +511,8 @@ example, since it lends itself well to that approach.
503511The first part of the program computes arrays of minimum column widths
504512and row heights from a collection of cells.
505513
514+ // include_code
515+
506516[source,javascript]
507517----
508518function rowHeights(rows) {
@@ -542,6 +552,8 @@ human readers) that this argument is not going to be used.
542552
543553Drawing a table now looks like this:
544554
555+ // include_code
556+
545557[source,javascript]
546558----
547559function drawTable(rows) {
@@ -574,6 +586,8 @@ Let us write a constructor for cells that contain text. The
574586constructor splits a string into an array of lines, and the `minWidth`
575587method finds the maximum line width in this array.
576588
589+ // include_code
590+
577591[source,javascript]
578592----
579593function repeat(string, times) {
@@ -643,6 +657,8 @@ We will want to emphasize the top row, which contains the column
643657names, by underlining the cells with a series of dash characters. No
644658problem, we simply write a cell type that handles underlining.
645659
660+ // include_code
661+
646662[source,javascript]
647663----
648664function UnderlinedCell(inner) {
@@ -772,6 +788,8 @@ We could simply write a whole new constructor, with all three methods
772788in its prototype. But prototypes may themselves have prototypes, and
773789this allows us to do something clever:
774790
791+ // include_code
792+
775793[source,javascript]
776794----
777795function RTextCell(text) {
@@ -808,6 +826,8 @@ Now if we slightly adjust the `dataTable` function to use
808826`RTextCell`'s for cells whose value is a number, we get the table we
809827were aiming for:
810828
829+ // include_code strip_log
830+
811831[source,javascript]
812832----
813833function dataTable(data) {
0 commit comments