This commit is contained in:
Ilya Kantor 2019-09-02 23:57:08 +03:00
parent b2cedf7b0a
commit ade541bd61
2 changed files with 4 additions and 3 deletions

View file

@ -1,11 +1,12 @@
function spy(func) { function spy(func) {
function wrapper(...args) { function wrapper(...args) {
// using ...args instead of arguments to store "real" array in wrapper.calls
wrapper.calls.push(args); wrapper.calls.push(args);
return func.apply(this, arguments); return func.apply(this, args);
} }
wrapper.calls = []; wrapper.calls = [];
return wrapper; return wrapper;
} }

View file

@ -1 +1 @@
Here we can use `calls.push(args)` to store all arguments in the log and `f.apply(this, args)` to forward the call. The wrapper returned by `spy(f)` should store all arguments and then use `f.apply` to forward the call.