I thought a prototype was a sort of “proto” object or something, but it turns out it’s just a property?
I’m confused… why is inheritance such a big deal with JS? (how does inheritance in JS differ from inheritance in Java?)
(I know all JS objects inherit from a sort of primal, “mother” Object… I used to think this “mother” object was the same as a prototype… now of course I’m realizing I’m wrong…
the reason am looking at this now is that I’ve been learning a lot of JSON lately (and thanks to help from fellow developers right here on SP I have learned a lot, and am finally comfy with JSON – yay!)
but I still have “lose ends”…
such as: how do you list the KEYS of an object in plain Javascript?
in jQuery it’s so simple, as you pass both the key and the value to the $.each() method; in plain, in this loop…
for (var i in data.users)
what exactly is “i”?? just the index of the kay-value pair, right?
something like
data.users[i].firstName
prints the value of the key “firstName”, but how do I print the KEY?
I’ve been reading up on this here…
http://stackoverflow.com/questions/208016/how-to-list-the-properties-of-a-javascript-object
(hence my q’s about prototypes…
I frankly don’t get any of the examples, tried a few, none worked…
I’m printing values thus:
for (var i in data.users) {
output+="<li>" + data.users[i].firstName + " " + data.users[i].lastName + " -- " + data.users[i].joined.month+"</li>";
}
so how do I do something like
for (var i in data.users) {
output+="<li>" + data.users[i].KEY"</li>";
}
???
I can’t believe how hard this is compared to the beauty of the jQuery $.each() method…:-o
meaning:
$.each(val, function(propName,propValue) {
divLeft.append(propName + '<br>');
});
and voila!! no fuss no muss…
thank you… HAPPY FOURTH OF JULY…
thank you…