console.log(key,'(', args.join(', '),') - was run')
return propOrMethod.apply(target, args);
}
}
}
}
This one is good for dealing with confusing classes with lots of method calls. It logs any time a method is called, what its name is and what arguments were passed to it. Sometimes this really beats stepping through breakpoints, at least in my experience…
This is useful when you know you need many methods of a given class to be bound to the classes instance. Another way to do this is to selectively use instance properties:
class Test {
constructor(){
document.addEventListener('click',this.onClick);
}
onClick = e =>{
console.log('click',this);
}
otherMethod e =>{
console.log('test',this);
}
}
Avoiding classes is another way to not have to deal with this issue 😉