Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
每次console.log执行时我都想做一些事情。我可以将事件侦听器添加到 console.log 还是猴子修补唯一的方法?如果猴子补丁是最好的方法,我如何在不创建无限递归的情况下进行猴子补丁?
console.log
您可以使用包装器函数来包装console.log 的行为。就像是:
const logWrapper = (logString) => { // DO SOMETHING HERE console.log(logString); }
并改为调用该新函数。您也可以更改 console.log 的定义,但我不建议这样做。