Higher order functions for working with functions in JavaScript