This way none of your functions get invoked except the one that you explicitly match.
You would probably want to throw a guard condition in there so you don't try to invoke undefined, but this would be my standard approach for anything that needs a dynamic list of functions that have external dependencies.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Yes indeed! The point is that we have to be careful about this technique because those aren't branches and are eagerly executed.
Wrapping it in a function solves the problem but it's not something we do with
if
statements, for example 😄Not sure about performance, but you can swap the immediate invocation for a
bind
. Eg:This way none of your functions get invoked except the one that you explicitly match.
You would probably want to throw a guard condition in there so you don't try to invoke
undefined
, but this would be my standard approach for anything that needs a dynamic list of functions that have external dependencies.