UNPKG

functional-javascript-workshop

Version:

The basics of functional programming in JavaScript. No libraries required.

20 lines (15 loc) 470 B
function Spy(target, method) { var originalFunction = target[method] // use an object so we can pass by reference, not value // i.e. we can return result, but update count from this scope var result = { count: 0 } // replace method with spy method target[method] = function() { result.count++ // track function was called return originalFunction.apply(this, arguments) // invoke original function } return result } module.exports = Spy