23.04.2013 Views

javascript

javascript

javascript

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

halfHalf: [2, "cup", "Organic Valley"],<br />

sugar: [5/8, "cup"],<br />

yolks: [6]<br />

};<br />

var Coffee = function(coffee) {<br />

this.coffee = coffee || [1/4, "cup, coarsely ground", "Starbucks Espresso"];<br />

};<br />

Coffee.prototype = new VanillaBean();<br />

var Chocolate = function(cocoa, bittersweet) {<br />

this.cocoa = cocoa || [3/16, "cup", "Callebaut"];<br />

this.bittersweet = bittersweet || [1 + 1/2, "cup", "Callebaut"];<br />

};<br />

Chocolate.prototype = new VanillaBean();<br />

Chocolate.prototype.yolks = [4];<br />

var MintChocolateChunk = function(mint) {<br />

this.mint = mint || [1, "cup", "fresh mint leaves"];<br />

};<br />

MintChocolateChunk.prototype = new Chocolate();<br />

MintChocolateChunk.prototype.vanilla = [1/3, "bean", "Madagascar Bourbon"];<br />

MintChocolateChunk.prototype.bittersweet[0] = 1;<br />

delete MintChocolateChunk.prototype.cocoa;<br />

var mintChocolateChunk = new MintChocolateChunk();<br />

console.dir(mintChocolateChunk);<br />

MintChocolateChunk.prototype.bittersweet[2] = "Lindt";<br />

console.dir(mintChocolateChunk);<br />

CHAPTER 5 ■ MEMBER INHERITANCE<br />

Figure 5–10. Changing MintChocolateChunk.prototype.bittersweet[2] from "Callebaut" to "Lindt" after<br />

creating mintChocolateChunk still changes its bittersweet member.<br />

161

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

Saved successfully!

Ooh no, something went wrong!