xdenser/node-struct — pull request #2 by jmcgill (2013-01-02 12:20:07+00:00)
Title: Fix for Issue #1 (Allows multiple structs to be safely allocated)

This patch moves 'beenHere' into the instance scope of Struct() as part
of the priv object, so that each Struct() has its own copy of the
variable. Today, all structs could share access to beenHere, so once one
has been allocated the applyClosures() method will never be run for
other structs.

Verified with the following code:

var Person = Struct()
.chars('firstName',10)
.chars('lastName',10)
.array('items',3,'chars',10)
.word16Sle('balance'),
People = Struct()
.word8('presentCount')
.array('list',2,Person);

Person.allocate();
People.allocate();

console.log(People.buffer());
console.log(Person.buffer());