Functional utility for invoking the same method on every call in JavaScript