Can't call public method while looping over object array
<p>I'm starting to play around a bit with OOP in JavaScript and I have an array of simple objects that I'm trying to loop over and call a method on each, however, when I run this under Google Chrome, I get the following exception in the JavaScript debugger:</p>

<pre>Uncaught TypeError: Object 0 has no method 'drawHisto'</pre>

<p>Simplified code snippet below:</p>

<pre class="lang-js prettyprint-override"><code>var histograms = [];
var h1 = null;
var h2 = null;
var h3 = null;

function Init() {
    h1 = new Histogram(canvas1, "red");
    h2 = new Histogram(canvas2, "blue");
    h3 = new Histogram(canvas3, "green");

    histograms = [ h1, h2, h3];
}

function Histogram(canvas, color) {
    // this is my constructor
}

Histogram.prototype.drawHisto = function() {
    // I will add code here to draw the histogram
}

function DrawHistograms() {
    for (var h in histograms) {
        h.drawHisto(); // Throws exception!
    }

    // h1.drawHisto() &lt;--- this works
}
</code></pre>

<p>Any idea what I might be doing wrong? I've simplified the code here a bit, so if you find that the problem must be elsewhere, I can add additional context.</p>

<p>Thank you.</p>
