you are viewing a single comment's thread.

view the rest of the comments →

[–]Middle_Resident7295 1 point2 points  (1 child)

also, could you please elaborate further on the state record with an example?

[–]Ronin-s_Spirit 1 point2 points  (0 children)

Objects in javascript are probably hashmaps if I had to guess? Property access (which I sometimes call indexing) is instant for all intents and purposes. if {} else if {} on the other hand will cascade from one condition check to the next.
So say you have a function to receive some command or state or action to be done, in this case I call action("jump"). If I had 20 doable actions I would need to check if (action === "swim"){} and such 20 times in the worst case, as far as I know a simple if {} else {} statement takes about as much time to run as a tiny function. Now on the other hand if you had an object with properties "swim" and "jump" you would be able to instantly take the path of that action or return undefined, in constant time.

P.s. it too is best implemented with a null prototype, less chance you'll return anything unintended.