This is an example from JavaScript:The Definitive Guide by David Flanagan
//Replace the method named m of the object o with a version that logs messages before and after invoking the original method.
function trace(o, m) {
var original = o[m]; // Remember original method in the closure.
o[m] = function() { // Now define the new method.
console.log(new Date(), "Entering:", m); // Log message.
var result = original.apply(this, arguments); // Invoke original.
console.log(new Date(), "Exiting:", m); // Log message.
return result; // Return result.
};
}
I understand that since m is a method of o, 'this' should refer to the object o. But I cannot understand how; because in a function 'this' should refer to the global object (non-strict mode).
Also, how does the 'arguments' array contain the original function's arguments and not of the anonymous wrapper function's?