Good morning, gentlemen. The code of the wrapper function adds the elements from the agruments the sum function into an argsArr array.
"use strict"; var argsArr = []; function funcLog(f, argsArr) { return function() { var wrapper = f.apply(this, arguments); var argsArrLocal = [].slice.call(arguments); for (var i = 0; i < argsArrLocal.length; i++) { argsArr.push(argsArrLocal[i]); } return wrapper; }; } function sum(a,b) { alert(a+b+b); } sum = funcLog(sum, argsArr); sum(2,3); alert(argsArr); The first version of the code was this.
"use strict"; var argsArr = []; function funcLog(f, argsArr) { return function() { var wrapper = f.apply(this, arguments); argsArr = [].slice.call(arguments); return wrapper; }; } function sum(a,b) { alert(a+b+b); } sum = funcLog(sum, argsArr); sum(2,3); alert(argsArr); But, he did not work. The array, argsArr , was not overwritten, and why I did not know. I suspect that I was mistaken somewhere, but I don’t understand the essence of the error. Direct on the right path.