JavaScript classes and enumeration
<p>I'm trying to understand enumerated types in JavaScript. Can someone help explain the code below?</p>

<p>I'm having difficulty understanding what is returned by the enumeration function (return enumeration)
Does this function return an object called Coin with four values?
Finally, what is the purpose of the dummy constructor on line 2/3?</p>

<pre><code> function enumeration(namesToValues) {
        // This is the dummy constructor function that will be the return value.
        var enumeration = function() { throw "Can't Instantiate Enumerations"; };


        var proto = enumeration.prototype = {
            constructor: enumeration,                   // Identify type
            toString: function() { return this.name; }, // Return name
            valueOf: function() { return this.value; }, // Return value
            toJSON: function() { return this.name; }    // For serialization
        };

        enumeration.values = [];  // An array of the enumerated value objects

        // Now create the instances of this new type.
        for(name in namesToValues) {         
            var e = inherit(proto);         
            e.name = name;                   
            e.value = namesToValues[name];   
            enumeration[name] = e;           
            enumeration.values.push(e);       
        }

        enumeration.foreach = function(f,c) {
            for(var i = 0; i &lt; this.values.length; i++) f.call(c,this.values[i]);
        };

        return enumeration;
    }



    var Coin = enumeration({Penny: 1, Nickel:5, Dime:10, Quarter:25});

    var c = Coin.Dime;                   // This is an instance of the new class
    c instanceof Coin                    // =&gt; true: instanceof works
    c.constructor == Coin                // =&gt; true: constructor property works
    Coin.Quarter + 3*Coin.Nickel         // =&gt; 40: values convert to numbers
    Coin.Dime == 10                      // =&gt; true: more conversion to numbers
    Coin.Dime &gt; Coin.Nickel              // =&gt; true: relational operators work
    String(Coin.Dime) + ":" + Coin.Dime  // =&gt; "Dime:10": coerce to string
</code></pre>