This allows one to iterate over all the properties of an object |
for ( variable in object ) { // Generic Form |
Bunch of statements } |
function dump_props(obj, obj_name) { |
var result = ""; |
for( var i in obj) { |
result += obj_name + "." + i + " = " + obj[i] + "<BR>"; } |
result += "<HR>"; |
return result; |
} |
Here i runs over names of Properties and obj[i] is actual property |
Note user supplies obj and obj_name |
function car(make,model) { // An Example |
this.make = make; |
this.model = model; } |
mycar = new car("Ford","Explorer"); |
document.writeln(dump_props(mycar,"mycar")); |