Notes
1Group (c) 2013 J MacPherson, some rights reserved↩
2A “Lisp-1” has a single namespace for both functions and other values. A “Lisp-2” has separate namespaces for functions and other values. To the extend that JavaScript resembles a Lisp, it resembles a Lisp-1. See The function namespace.↩
3Mazzer Mini Grinder, some rights reserved↩
4JavaScript does not actually pass functions or any other kind of object around, it passes references to functions and other objects around. But it’s awkward to describe var I = function (a) { return a; } as binding a reference to a function to the variable I, so we often take an intellectually lazy shortcut, and say the function is bound to the variable I. This is much the same shorthand as saying that somebody added me to the schedule for an upcoming conference: They really added my name to the list, which is a kind of reference to me.↩
5This exercise was snarfed from The Four Rules of Simple Design↩
6Transparent Sanremo espresso machine, London Coffee Festival, Truman Brewery, Brick Lane, Hackney, London, UK (c) 2013 Cory Doctorow, some rights reserved↩
7These function names go back to Lisp 1.5. The story is that it was written for a hardware architecture that had two fast CPU registers, an address register and a decrement register. The core data type was called a “cons cell,” and represented two pointers. One was stored in the address register, the other in the decrement register. The function car meant “contents of address register,” and the function cdr meant “contents of the decrement register.” cons meant “create a new cons cell.” The would have called map “mapcar,” but we’re sticking with the more contemporary term.↩
8“A language construct that facilitates the bundling of data with the methods (or other functions) operating on that data.”–Wikipedia↩
9Yes, there’s another way to track the size of the array, but we don’t need it to demonstrate encapsulation and hiding of state.↩
10And when you take an already factored component and rearrange things so that it is factored into a different set of subcomponents without altering its behaviour, you are refactoring.↩
11Before you start wondering whether a deque is-a queue, we said nothing about types and classes. This relationship is called was-a, or “implemented in terms of a.”↩
12JavaScript also does other things with this as well, but this is all we care about right now.↩
13Too bad the language binds the context to the name this instead of the name context!↩
14Just enough to be frustrating, to be perfectly candid!↩
15Londinium 1 Lever Espresso Machine (c) 2013 Alejandro Erickson, some rights reserved↩
16JavaScript also provides a single method that can close an object for modification, extension, and configuration at the same time: Object.freeze(...).↩
17Vacuum Pots (c) 2012 Olin Viydo, some rights reserved↩
18For many programmers, the distinction between a dynamic relationship and a copying mechanism is too fine to worry about. However, it makes many dynamic program modifications possible.↩
19Recall that Strings, Numbers, Booleans and so forth are value types and primitives. We’re calling them primitives here.↩
20Mmm … Vivace’s Espresso! (c) 2004 Allan Haggert, some rights reserved↩
21Later on, we’ll see how to use method combinators to do this more elegantly.↩
22With the greatest respect to Chongo, author of “The Homeless Interpretation of Quantum Mechanics.”↩
23Robert Martin’s rule of thumb for determining whether a method has a single responsibility is to ask when and why it would ever change. If there is just one reason why you are likely to change a method, it has a single responsibility. If there is more than one reason why it might change, it should be decomposed into separate entities that each have a single responsibility.↩
24Krups Machines (c) 2010 Shadow Becomes White, some rights reserved↩
25Transpile-to-JavaScript languages like CoffeeScript, and the upcoming EcmaScript 6 verison of JavaScript provide destructuring to help with the syntax of things like named parameters. But the mechanism is identical.↩
26London Interlude (c) 2007 Bolshakov, some rights reserved↩
27we’ll see the same issues with context and self again in Encapsulation and Self.↩
28Nespresso Capsules (c) 2011 André Nieto Porras, some rights reserved↩
29This example of the Extract Method refactoring comes from Martin Fowler’s excellent Catalogue of Refactorings.↩
30We will deliberately leave out some refinements such as self and private methods to highlight the ideas we’re exploring here.↩
31Royal Java Distributed by the Boston Public Library, no known rights.↩
32image (c) 2010 Christina Spicuzza. Some rights reserved↩
33image (c) 2011. Some rights reserved↩
34Cime Espresso Machine Factory, Copyright 2012, Jong Hoon Lee Some Rights Reserved↩
35Coffee Chart (c) 2012 Michael Coghlan, some rights reserved↩