monzay

Need help in understanding this function

Discussion created by monzay on Nov 4, 2011
Latest reply on Nov 4, 2011 by jeff.pace
I have questions about the code below. It is part of this example:

I added comments/questions in for myself.

var testVals={}; // create object literal (shortcut to creating a new object). This is to hold name:value pairs because an array can only hold single values?


var features = results.features; //features is a property of query task and has the type of 'graphic'. It is an array.
        dojo.forEach (features, function(feature) { //optimized way of doing a for loop, specific to dojo, patterned after HTML5. Let's you apply a function to each element of an array. Feature is each item in the array.
          zone = feature.attributes.ZONING_TYPE; //feature in this context is a graphic and attributes is a property
if (!testVals[zone]) { //tests to see if the name:value pair exists
            testVals[zone] = true; //if it it doesn't exist then set this object to true?
            values.push({name:zone}); //push the name:pair of name:<value of zoning type> into the object literal
          }


So, if zone has a value of 'residential' then when it gets tested in the if statement, is it testing to see if that value is contained in the testval object? Is it saying, "if zone value does not exist then set that value to true? I'm not exactly sure what exactly is getting set to true and why? Then, it pushes that value into the testval object using name:zone as the pair.

Outcomes