Home

The Secret Link!

Posted on January 28th, 2007 in The Art of Computer Programming by Jorge Luis

Welcome to…The Secret Link!

In this game, the chain is composed of hashtables (JavaScript objects) related to each other by means of, yes, you guessed it, secret links.

That’s how Douglas Crockford explains JavaScript’s prototypal inheritance in this excellent set of talks now playing at your nearest YUI Theater.

So, given:

var myNewObject = object(youSir);

then, myNewObject has …A Secret Link!…to youSir.

This secret link is followed only when reading an object’s properties. So, say youSir had been defined thusly:

var youSir =
{
name: “Jack B. Nimble”,
grade: “A”,
level: 3
};

then myNewObject.name returns “Jack B. Nimble”. From what hat did myNewObject pull that rabbit, you may ask, after all, myNewObject itself does not have a property called “name!” It’s The Secret Link, stupid! Since looking up “name’s” value directly from myNewObject fails…The Secret Link!…to youSir is used to look up the same property in youSir, which, luckily has that property. Otherwise, youSir’s…Secret Link!…to its parent would have been consulted, applying, lathering, rinsing, and repeating until Object.prototype would’ve been reached, which if it also had no such property would finally have returned…undefined!

However, assignment does not involve…The Secret Link! The assignment,

myNewObject.name = “Johnny B. Goode”;

does not change the value of youSir.name. Instead, it adds the property “name” to myNewObject with the given value, such that mNewObject.name returns “Johnny B. Goode” and youSir.name returns “Jack B. Nimble”.

Pop quiz: What is the result of

myNewObject.level += 1; ?

Answer:

  1. myNewObject.level does not have a property named “level”, so its…Secret Link!…to youSir is used to look up youSir’s level value, namely 3.
  2. 3 is added to 1, yielding 4.
  3. Then a property named “level” is added to myNewObject and assigned the value 4!

That, sir, is JavaScript’s protoypal inheritance in a nutshell, secretly linked hashtables.

Florida, Shark Attack Capital of the World

Posted on January 23rd, 2007 in Small Talk by Jorge Luis

Surprisingly, Florida leads the world in shark attacks by a good margin.

Reuters reports:

The U.S. state of Florida annually records by far the most shark attacks.

Between 1990 and 2005 there were 341 shark attacks off Florida, according to the U.S.-based International Shark Attack File, www.flmnh.ufl.edu/fish/Sharks/ISAF/ISAF.htm.

Over the same period, Australia reported 74 attacks, South Africa 72, Brazil 62 and Hawaii 57.

What the U.S. Can Learn from Chile

Posted on January 7th, 2007 in Politics by Jorge Luis

Speaking of Chile, check out this Cato Institute interview with José Piñera in which he argues for applying Chilean-style pension reform. Whether you buy into his plan or not, it’s hard to argue against his goal, “libertad para los pobres” (freedom for the poor), save to make the statement more precise, “liberate the poor from poverty.”

Dictator Exits Stage Right. Dictator Exits Stage Left.

Posted on January 7th, 2007 in Cuba, Politics, Human Rights by Jorge Luis

Last month, former Chilean dictator Augusto Pinochet died, and a friend asked me for my perspective on Pinochet, to which I replied:

As Hitler made the trains run on time, Pinochet saved Chile from Cuba’s fate. The guy was a ruthless dictator, pure and simple. But would Chile had been better off with Allende? I doubt it. They were both terrible (and false) choices. Humane means existed to deliver Chile the thriving economy and political freedoms it now enjoys.

Maria Elvira, a Spanish-language journalist, interviewed both Pinochet and Castro. The one thing she saw in common was their equal and absolute certainty in the rightness of what they’d done. A tyrant is a tyrant, no matter what band of the political spectrum he occupies.

What’s in a Name?

Posted on January 7th, 2007 in Small Talk by Jorge Luis

I thought giving your kids really weird and/or made-up names was strictly a recent Cuban phenomenon, but it turns out Venezuelans do it too.
http://www.iht.com/articles/2007/01/07/news/venez.php?page=1