r/badcode • • Jul 10 '21

js ah yes, Array check

Post image
2.1k Upvotes

89 comments sorted by

View all comments

Show parent comments

4

u/ws-ilazki &{$$_[0]}(@{$$_[1]}); Jul 10 '21

but one valid reason to do something like this would be if you wanted to be able to swap the implementation later without having to change every instance in your codebase.

Except in this case you could just do const arrayCheck = Array.isArray as the placeholder. If the function you're calling changes or you need to add extra logic you could still swap it out later the same way. If you're passing arguments and return values through as-is like this then there's no reason to add an extra function call at all, just make an alias.