How to implement Swift-like enums with associated values in JavaScript?
<p>The Swift language has a fantastic enum support. Not only can one define a standard enum with cases, but cases can have optional values "associated to them."</p>

<p>For example, taken from the Swift docs:</p>

<pre><code>enum Barcode {
    case UPCA(Int, Int, Int, Int)
    case QRCode(String)
    case Other
}
</code></pre>

<p>Such that one could create a Barcode enum by passing in a value, like so:</p>

<p><code>var productBarcode = Barcode.UPCA(8, 85909, 51226, 3)</code></p>

<p>and also <code>switch</code> on <code>productBarcode</code> at a later date to retrieve the associated value (a tuple of <code>int</code>s).</p>

<hr>

<p>I have been trying to implement this kind of <code>enum</code> system in JavaScript (ES5, in particular), but am hitting a wall. What is the best way to structure an enum system, especially one with associated values?</p>