In Javascript: Losing type of object when passed from Array?
<p>I'm passing an object of a certain type to an array.
When I print the object from an outside reference I can see all the fields.
When I print the same object from the array reference, I see almost none.</p>

<p>To Explain, here is the code that illustrates the problem:</p>

<pre><code>var test = new OpenLayers.Layer.Vector();

var array = [test];

console.log("******* Printing Test directly ***************");
printObjectProperties(test);

console.log("****** Printing Test from array **************");
for (obj in array){
    printObjectProperties(obj);     
}
</code></pre>

<p>The <code>printObjectProperties()</code> function:</p>

<pre><code>function printObjectProperties(eventData) {
        for (var prop in eventData) {
            if (!(typeof (eventData[prop]) == "undefined")) {
                console.log(prop + " = " + eventData[prop]);
            }
        };
}
</code></pre>

<p>The complete code (complete html file, you can run and see for youself in the browser console log):
(<a href="http://jsbin.com/evazip/2/edit" rel="nofollow">live example</a>)</p>

<pre><code>&lt;html&gt;
&lt;script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"&gt;&lt;/script&gt;
&lt;script src="http://www.openlayers.org/api/OpenLayers.js"&gt;&lt;/script&gt;
&lt;script&gt;

    $(document).ready(function(){

        var test = new OpenLayers.Layer.Vector();

        var array = [test];

        console.log("******* Printing Test directly ***************");
        printObjectProperties(test);

        console.log("****** Printing Test from array **************");
        for (obj in array){
            printObjectProperties(obj);     
        }

    });


function printObjectProperties(eventData) {
        for (var prop in eventData) {
            if (!(typeof (eventData[prop]) == "undefined")) {
                console.log(prop + " = " + eventData[prop]);
            }
        };
}

&lt;/script&gt;
&lt;/html&gt;
</code></pre>
