Assigning a unique id in Javascript
<pre><code>$ var Node = function(){ this.someval = 0; }
undefined
$ var node = new Node();
undefined
$ node.someval
0
$ Node.next_id = 0
0
$ Node.prototype.constructor = function() { this.someval = Node.next_id++; }
function () { this.someval = Node.next_id++; }
$ var node2 = new Node();
undefined
$ node2.someval
0
$ var node3 = new Node();
undefined
$ node3.someval
0
</code></pre>

<p>Why doesn't next_id++ work as expected? I expected next_id to increment with every call to <code>new Node()</code> and thus assign a new id to each node.</p>
