Have you all read Douglas Hofstadter’s beautiful Gödel, Escher, Bach: An Eternal Golden Braid? You should go get your copy. If you don’t have one yet, you can take one home for your very self here. I’ll wait. The internet always waits.
Ok! Remember the terrific inter-chapter dialogues between the Tortoise and Achilles? Remember the one about pushing and popping, meta-Genies, and the Majotaur, “Little Harmonic Labyrinth”? Page 103 in the 20th Anniversary edition. Hofstadter was something of a computer scientist (while being rather disinterested in programming itself), so it’s no surprise that the mathematics of this dialogue (and indeed of the entirety of the delightfully dense GEB) read like a computational theory problem wrapped up in a Lewis Carroll witticism (whom Hofstadter adores and references frequently in the book).
I’m getting lost in the book, as I so often do : ) but my point here, other than urging you to GO! GO! READ THIS BOOK! IT’S HARD AND THAT’S OK! is that javascript’s class inheritance reminds me just a bit of this airy idea of pushing and popping from world to world. Each class is its own world, and pushing from that class is another class that can only come from the initial one.
function Feline = (name, type) { this.name = name; this.type = type; };
Now let’s add a method to this class:
Feline.prototype.infoPrint = function() { for (var i in Feline) { console.log(Feline.i); } };
And now, let’s make a new thing altogether. Notice the third attribute:
function DSH = (name, type) { this.name = name; this.type = type; this.color = color;
And now! Since we know that Domestic Short Haired cats are a kind of Feline
, let’s make it so officially, and actually CREATE an animal out of this!!
DSH.prototype = new Feline(); var morris = new DSH("Morris", "ornery", "buff and white");
Also notice that only objects created from constructor DSH
will have the attribute color
, but the regular Feline
class will not. DSH
is a push down from Feline
, and divining objects from the constructor DSH
will only give us specific DSHs, which have all the characteristics of Feline
as well (though I believe those are specially mutable even after you’ve defined them, but more on that later, when I understand better too [which I am pretty sure can be strung into the metaphor of popping, perhaps?!] : ))!
So, go ye, and read of Gödel, Escher, Bach: An Eternal Golden Braid and tell me what beautiful mathematic or programmatic relation he makes you think of, and, likely, consider in a whole new way!
Last thing: once, on the train (a multi-day, cross-country trip), I had that book in my hand, waiting to get a morning coffee so I could sit and read it (I’ve still only read up to page ~130), and a gal came up to me and said “I read that book thirty years ago, and I’ve been reading it ever since.” Still the finest commendation for a book that I’ve ever heard.