Skip to content

Instantly share code, notes, and snippets.

@devotdev
Last active August 29, 2024 13:30
Show Gist options
  • Select an option

  • Save devotdev/a326d0a2e2ba39267afb3652ed65f269 to your computer and use it in GitHub Desktop.

Select an option

Save devotdev/a326d0a2e2ba39267afb3652ed65f269 to your computer and use it in GitHub Desktop.
function log(target: any, methodName: string, descriptor: PropertyDescriptor) {
const originalMethod = descriptor.value;
descriptor.value = function (...args: any[]) {
console.log(Method ${methodName} called with arguments: ${JSON.stringify(args)});
console.log(`State before method ${methodName}: ${JSON.stringify(this)}`);
const result = originalMethod.apply(this, args);
console.log(Method ${methodName} returned: ${JSON.stringify(result)});
return result;
};
return descriptor;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment