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.

(function () {<br />

var clone = typeof Object.create === "function" ?<br />

function (donor) {<br />

return typeof donor !== "function" ?<br />

Object.create(donor) :<br />

Object.create(new donor());<br />

} :<br />

function (donor) {<br />

var Proxy = function () {};<br />

Proxy.prototype = typeof donor !== "function" ?<br />

donor :<br />

new donor();<br />

return new Proxy();<br />

};<br />

var SweetCream = function () {};<br />

SweetCream.prototype = {<br />

heavyCream: [1, "cup", "Organic Valley"],<br />

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

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

yolks: [6]<br />

};<br />

}());<br />

console.dir(clone(SweetCream));<br />

Figure 6–23. clone() and SweetCream() are not globally defined.<br />

CHAPTER 6 ■ FUNCTIONS AND ARRAYS<br />

229

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

Saved successfully!

Ooh no, something went wrong!