Javascript - Override console.log and keep the old function

前端 未结 8 1169
春和景丽
春和景丽 2021-01-12 08:49

I would like to override console.log and call it on my new function.

I try something like this but I get Uncaught TypeError: Illegal invocation:

8条回答
  •  有刺的猬
    2021-01-12 09:38

    One little point... console.log can receive multiple arguments, for example:

    console.log('results', result1, result2, result3);
    

    If you want this behavior, you can do something like this:

    console.log = function(){
        var args = Array.from(arguments).join(' ');
        ...
    }
    

提交回复
热议问题