3 ms·
As others have said, this pattern is used for pattern matching when the language doesn't have specific constructs for it. When I use it, I will extract it into
by rhinoceraptor 7y ago
As others have said, this pattern is used for pattern matching when the language doesn't have specific constructs for it.
When I use it, I will extract it into a separate function, and just return the needed condition. That way you don't need to worry about case fall through.
function getCondition(param) {
switch (true) {
case ConditionOne(param): return 'condition one'
case ConditionTwo(param): return 'condition two'
case ConditionThree(param): return 'condition three'
}
}