17.11.2015 Views

JavaScript_Succinctly

Create successful ePaper yourself

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

In the following example, I examine the properties of the window object.<br />

Sample: sample45.html<br />

<br />

for (x in window) {<br />

console.log(x); // Logs all of the properties of the window/head<br />

object.<br />

}<br />

<br />

You might have noticed that native <strong>JavaScript</strong> objects are not listed among the host<br />

objects. It’s fairly common that a browser distinguishes between host objects and native<br />

objects.<br />

As it pertains to web browsers, the most famous of all hosted objects is the interface for<br />

working with HTML documents, also known as the DOM. The following sample is a<br />

method to list all of the objects contained inside the window.document object provided<br />

by the browser environment.<br />

Sample: sample46.html<br />

<br />

for (x in window.document) {<br />

console.log();<br />

}<br />

<br />

What I want you to learn here is that the <strong>JavaScript</strong> specification does not concern itself<br />

with host objects and vice versa. There is a dividing line between what <strong>JavaScript</strong><br />

provides (e.g., <strong>JavaScript</strong> 1.5, ECMA-262, Edition 3 versus Mozilla's <strong>JavaScript</strong> 1.6, 1.7,<br />

1.8, 1.8.1, 1.8.5) and what the host environment provides, and these two should not be<br />

confused.<br />

Notes<br />

The host environment (e.g., a web browser) that runs <strong>JavaScript</strong> code typically provides<br />

the head object (e.g., window object in a web browser) where the native portions of the<br />

language are stored along with host objects (e.g., window.location in a web browser)<br />

and user-defined objects (e.g., the code you write to run in the web browser).<br />

57

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

Saved successfully!

Ooh no, something went wrong!