a function to reset the method to its previous, unwrapped state
// log all get requests to the console
wrapMethod(HttpClient.prototype, "get", {
before(url) {
console.log("Sending GET request to", url);
}
});
// suppress benign error messages
const unwrap = wrapMethod(console, "error", {
around(original, ...args) {
if (args[0].message !== 'something benign') {
original(...args);
}
}
});
// remove error suppression (from above)
unwrap();
Replaces a method on
objectwith a wrapped version that will call the provided hooks in addition to the original method. SeewrapFunction()for more details on the hooks.