News for hackers. Stuff that matters.
Re:Construct-JS – A library for creating byte level data str... by javajosh on Monday March 18, 2019 @06:55AM (#19420064)
They could have used a Map (introduced in ES6 [1]) which maintains key insertion order. However, I'm not sure whether either the object or map interface would be significantly better or worse than the builder-style the author picked. It just doesn't seem to matter, IMO.

The interface that would be most flexible would probably be a list of alternating key values, e.g. ['fieldname', datastruct(), 'fieldname'] since then you could do all the list things to it.

[1] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...

Re:Construct-JS – A library for creating byte level data str... by gridlockd on Monday March 18, 2019 @07:04AM (#19420103)
The underlying structure is not the issue, it's the object literal that doesn't have its key order defined (in older standards) and therefore the interface as suggested would be broken.

In practice the order will be maintained in the major engines, but that's still not a good reason to do rely on it.

Re:Construct-JS – A library for creating byte level data str... by shawnz on Monday March 18, 2019 @08:57AM (#19420634)
I think the parent is suggesting taking a map instead of an object as the interface for constructing the Struct objects. Not using it as the underlying structure.
Re:Construct-JS – A library for creating byte level data str... by FrancisStokes on Monday March 18, 2019 @09:34AM (#19420847)
Map wouldn't have really brought a lot of clarity or control. You'd have to specify an array of array-pairs, which is noisy IMO, and then you wouldn't have the benefit of being able to programatically/conditionally add fields.

I might consider a static `Struct.fromMap(name, mapObject)`, but as a complimentary API.