Quit wrapping and start binding
Delaying function execution with .bind
Usually the less code we have to write, the easier it will be to debug and reason about our application.
Take the following code for example:
It’s pretty straight forward but, it also contains a lot of unnecessary function declarations. We’re using 3 anonymous functions solely to delay the execution of the setState function .
Thankfully we can cleanup and refactor those anonymous function wrappers by replacing them with the .bind method:
By removing all those function wrappers we’re left with code that’s much shorter and easier to (debug) read.