Can I extend the console object (for rerouting the logging) in javascript?

前端 未结 6 1852
误落风尘
误落风尘 2020-11-30 08:33

Is it possible to extend the console object?

I tried something like:

Console.prototype.log = function(msg){
    Console.prototype.log.call(msg);
             


        
6条回答
  •  孤独总比滥情好
    2020-11-30 09:23

    Try following:

    (function() {
        var exLog = console.log;
        console.log = function(msg) {
            exLog.apply(this, arguments);
            alert(msg);
        }
    })()
    

提交回复
热议问题