in struct.js [29:59]
function StructRW(cons, fields, opts) {
if (!(this instanceof StructRW)) {
return new StructRW(cons, fields);
}
if (typeof cons === 'object') {
fields = cons;
cons = null;
}
var i;
opts = opts || {};
this.cons = cons || Object;
this.fields = [];
// TODO: useful to have a StructRWField prototype?
if (Array.isArray(fields)) {
this.fields.push.apply(this.fields, fields);
} else {
var fieldNames = Object.keys(fields);
for (i = 0; i < fieldNames.length; ++i) {
var field = {};
field.name = fieldNames[i];
field.rw = fields[field.name];
this.fields.push(field);
}
}
this.namedFields = {};
for (i = 0; i < this.fields.length; ++i) {
if (this.fields[i].name) {
this.namedFields[this.fields[i].name] = this.fields[i];
}
}
}