重写console.log()实现自己的逻辑

// console.log 重写
console.log = (function(oriLogFunc){
    return function(str,str1)
    {
        if(str1 == undefined){
            oriLogFunc.call(console,str);
        }else{
            mui.ajax('url', {
                data: {
                    content: str
                },
                dataType: 'json', //服务器返回json格式数据
                type: 'post', //HTTP请求类型
                timeout: 10000, //超时时间设置为10秒;
                headers: {
                    'Content-Type': 'application/x-www-form-urlencoded'
                },
                success: function(data) {},
                error: function(xhr, type, errorThrown) {
                    //异常处理;
                    console.log(type);
                }
            });
        oriLogFunc.call(console,str,str1);
        }
            
    }
})(console.log);
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容