You can pass the original function to an anonymous function that returns a replacement function that has access to the original function.
eg.
parseInt = (function parseInt(original) {
return function (x) {
console.log("original would've returned " + original(x));
return (x | 0) * 2;
};
}(parseInt));
Output Example:
>> parseInt(10);
<< original would've returned 10
<< 20
source
share