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.

CHAPTER 6 ■ FUNCTIONS AND ARRAYS<br />

Object.defineProperties = function (obj, descriptors) {<br />

for (descriptor in descriptors) {<br />

if (descriptors.hasOwnProperty(descriptor)) {<br />

obj[descriptor] = descriptors[descriptor].value;<br />

}<br />

}<br />

};<br />

}<br />

if (Object.create === undefined) {<br />

Object.create = function (parent, descriptors) {<br />

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

child;<br />

Proxy.prototype = parent;<br />

child = new Proxy();<br />

if (descriptors !== undefined) {<br />

Object.defineProperties(child, descriptors);<br />

}<br />

return child;<br />

};<br />

}<br />

Function.prototype.bind = Function.prototype.bind ||<br />

function (obj) {<br />

var that = this;<br />

};<br />

By way of the comma operator, define another variable named ossify. Then borrow the slice()<br />

method from an empty array literal with the call() method, which slice() inherits from<br />

Function.prototype as any other function would. Then we’ll invoke slice() in order to save any<br />

unnamed arguments passed to bind() as an array. So, ossify does not contain obj, just any additional<br />

arguments.<br />

if (Object.defineProperties === undefined) {<br />

Object.defineProperties = function (obj, descriptors) {<br />

for (descriptor in descriptors) {<br />

if (descriptors.hasOwnProperty(descriptor)) {<br />

obj[descriptor] = descriptors[descriptor].value;<br />

}<br />

}<br />

};<br />

}<br />

if (Object.create === undefined) {<br />

Object.create = function (parent, descriptors) {<br />

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

child;<br />

Proxy.prototype = parent;<br />

child = new Proxy();<br />

if (descriptors !== undefined) {<br />

Object.defineProperties(child, descriptors);<br />

}<br />

return child;<br />

};<br />

}<br />

Function.prototype.bind = Function.prototype.bind ||<br />

function (obj) {<br />

209

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

Saved successfully!

Ooh no, something went wrong!