11.12.2012 Views

JavaScript 2.0-The Complete Reference, Second ... - freecodingtutorial

JavaScript 2.0-The Complete Reference, Second ... - freecodingtutorial

JavaScript 2.0-The Complete Reference, Second ... - freecodingtutorial

SHOW MORE
SHOW LESS

Create successful ePaper yourself

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

Indeed, Mozilla shows more properties (see Figure 6-2), but they‘re not exactly what you might<br />

expect either.<br />

Figure 6-2: Mozilla supports array-style indexing of strings.<br />

A final wrinkle to be aware of is that the order in which properties are enumerated is undefined.<br />

That is, there‘s no guarantee as to the relative order in which they‘ll be assigned to the loop<br />

variable, nor that the order will be consistent from one for/in loop to the next.<br />

<strong>The</strong>se facts, particularly that only instance properties are usually enumerated, mean that for/in<br />

loops are primarily useful with user-defined objects, where you‘ve set instance properties and<br />

know there are none that are preexisting. <strong>The</strong>se loops are often also helpful, particularly when<br />

debugging, and can also be used to satisfy your curiosity; many browsers implement<br />

undocumented properties that can be useful if one knows they exist.<br />

Using with<br />

Another convenient object-related operator is with:<br />

with (object)

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

Saved successfully!

Ooh no, something went wrong!