The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

mszczepaniak (4) [Avatar] Offline
#1
The second to the last paragraph in section 1.3.6 says the following:

The x in the loop is the attribute name, and person[x] is the same as using the
person["name"] syntax above to show the value of that attribute of the object.


The way this is written is very confusing. x is not the just the name attribute. It is a pointer to all the attributes in the person object. I'm sure that this is what you meant, but I had to stare at this awhile and create the following page to clarify this point:

<!doctype html>
<html>
<script type="text/javascript" src="d3.min.js"></script>
<script type="text/javascript">
var person = {name: "Charlie", age: 55, employed: true, childrenNames:["Ruth", "Charlie Jr."]};
for (x in person) {console.log(x); console.log(person[x]);}
</script>

<body>
running script from section 1.3.6...
</body>
</html>


The (Firebug) console output looks like this:

name
Charlie
age
55
employed
true
childrenNames
["Ruth", "Charlie Jr."]


I'd rewrite this paragraph as follows:

The x in the loop represents each attribute in the person object. Each x will be one of the attributes such as person["name"], person["age"], etc.
mszczepaniak (4) [Avatar] Offline
#2
Re: Section 1.3.6
I reread this a few more times and realize that your original explanation is probably fine. "... using the person["name"] syntax..."

I got tripped up on the distinction between the name of the attribute and the "name" attribute itself. Sorry.

clarification