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:

An example where unneeded anonymous function wrappers are being used on toggle, setActive and setInactive.

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:

An example where we’ve replaced the anonymous function wrappers with .bind

By removing all those function wrappers we’re left with code that’s much shorter and easier to (debug) read.