HELP! * GREY=local LOCAL HTML version of Foils prepared 15 January 1997

Foil 30 The for ... in JavaScript syntax

From JavaScript Tutorial for CPS616 Technologies of the Information Age 1997 Basic Information Track of CPS -- Spring Semester 97. by Geoffrey C. Fox * Important Information in IMAGE

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"));



Northeast Parallel Architectures Center, Syracuse University, npac@npac.syr.edu

If you have any comments about this server, send e-mail to webmaster@npac.syr.edu.

Page produced by wwwfoil on Wed Feb 19 1997