DEV Community

Discussion on: Use lookup tables for cleaning up your JS/TS code

Collapse
 
seanmclem profile image
Seanmclem

Why is this referred to as a lookup table, when it's just a plain old object with values retrieved by keys like with any object?

Collapse
 
williamfrank profile image
WilliamFrank • Edited

You are right, that from a syntactic point of view, this is a plain old object. A pattern, like the lookup table pattern, is a reusable solution to a commonly occurring problem.

The problem, in this case, is how to express a set of exclusive choices so that the code goes directly to the right choice, without evaluating any of the irrelevant choices, making the code shorter, clearer, and more efficient. What makes this object a 'lookup table' is not its syntax, but the purpose to which it is being put (its pragmatics).
Other plain old objects may have very different purposes. Every pattern must use some ordinary js syntactic structures, otherwise, they could not execute. The pattern is not about 'what' but about 'why'.