How to safely wrap `console.log`?

后端 未结 10 523
日久生厌
日久生厌 2021-01-31 14:13

Suppose I want to include some calls to console.log for some legitimate production reason, say for something like a unit test harness. Obviously I would not want th

10条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-31 15:12

    Paul Irish has a nice light wrapper/replacement for console.log().

    http://paulirish.com/2009/log-a-lightweight-wrapper-for-consolelog/

    Advantages:

    • Prevent errors if a console isn’t around (i.e. IE)
    • Maintains a history of logs, so you can look in the past if your console is added afterwards (e.g. firebug lite)
    • Light & simple.
    • Very quick to type -- log() or window.log().

提交回复
热议问题