/** * This accepts an optional `f` implementation, and it returns a function * with two extra properties: * * - `called` - the number of times this function has been called. * - `calls` - an array of `this` + `args` objects, representing each call. */ function makeSpy(f) { /** @this */ function spy() { var args = [] for (var i = 0; i < arguments.length; i++) { args.push(arguments[i]) } spy.called++ spy.this.push(this) spy.args.push(args) if (f != null) return f.apply(undefined, arguments) else return undefined } spy.called = 0 spy.this = [] spy.args = [] return spy }