23.04.2013 Views

javascript

javascript

javascript

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

C H A P T E R 6<br />

■ ■ ■<br />

Functions and Arrays<br />

In the previous chapter, you learned about inheritance and saw how to pass members onto child objects<br />

using classical, prototypal, deep copy, and mixin inheritance. As I noted at the end of that chapter, it’s<br />

actually functions that are more often passed on to child objects. This is because common processes, as<br />

provided by a function, are frequently more useful than common data, as provided by members. In this<br />

chapter, I’ll cover why you would want to use functions and how to take advantage of function<br />

inheritance. There are a lot of cool tricks to learn in this area and we’ll take advantage of a lot of them in<br />

later chapters, as you’ll see from the copious forward references. In other words, this is quite an<br />

important chapter.<br />

In addition to the function subtype, arrays are a second subtype of the object value type. Arrays are<br />

special primarily due to the predefined methods they inherit from Array.prototype. We’ll explore those<br />

methods in this chapter.<br />

Why Use Functions?<br />

Ben & Jerry’s, Häagen-Dazs, and other French-style ice creams are made by creating a satiny custard<br />

from cream, milk, and egg yolks. Compared to Philadelphia-style ice cream, which is made by simply<br />

churning cream and milk, French-style ice cream can be tricky for a beginner to make. So, it’s best to<br />

start with vanilla before gilding the lily. Err, gilding the orchid—vanilla flavoring derives from the fruit of<br />

the vanilla orchid.<br />

Anyway, the most delicious vanilla ice cream is made by steeping the pod and seeds from a vanilla<br />

bean rather than by stirring in vanilla extract, which is less flavorful. Vanilla beans differ in taste<br />

depending on where the vanilla orchids are grown. Madagascar Bourbon are my favorite. Compared to<br />

those, Tahitian are milder in flavor, and Mexican are bolder.<br />

If you are an ice-cream beginner, take your lumps with the following recipe for French vanilla before<br />

gilding the orchid with chocolate, fruit, and so on:<br />

1 cup, Organic Valley heavy whipping cream<br />

2 cups, Organic Valley half & half<br />

5/8 cup, sugar<br />

6 egg yolks<br />

1 Madagascar Bourbon vanilla bean<br />

• Separate the egg yolks into mixing bowl.<br />

• Slit the vanilla bean length-wise with a paring knife.<br />

• Scrape the tiny, pasty seeds into a saucepan. Then add the empty pod halves—<br />

most of the vanilla flavor derives from the pod.<br />

• Add 2 cups half & half, 1/2 cup heavy whipping cream, and 5/8 cup sugar to<br />

saucepan containing the vanilla seeds and pod halves.<br />

181

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!