久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如果未定義,js 會覆蓋 console.log

js override console.log if not defined(如果未定義,js 會覆蓋 console.log)
本文介紹了如果未定義,js 會覆蓋 console.log的處理方法,對大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

您推薦哪種解決方案,第二種更簡單(代碼更少),但使用它有缺點(diǎn)?

Which solution do you recommend, the second is simpler ( less code ), but there are drawbacks on using it ?

首先:(設(shè)置全局調(diào)試標(biāo)志)

// the first line of code
var debug = true;
try {
    console.log
} catch(e) {
    if(e) {
        debug=false;
    }
};
// Then later in the code
if(debug) {
    console.log(something);
}

第二:覆蓋console.log

Second: override console.log

try {
    console.log
} catch(e) {
    if (e) {
        console.log = function() {}
    }
};
// And all you need to do in the code is
console.log(something);

推薦答案

不是,而是第二種的變體.丟失 try...catch 并正確檢查控制臺對象是否存在:

Neither, but a variation of the second. Lose the try...catch and check for existence of the console object properly:

if (typeof console == "undefined") {
    window.console = {
        log: function () {}
    };
}

console.log("whatever");

這篇關(guān)于如果未定義,js 會覆蓋 console.log的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

How to fix BrowserWindow is not a constructor error when creating child window in Electron renderer process(在 Electron 渲染器進(jìn)程中創(chuàng)建子窗口時如何修復(fù) BrowserWindow 不是構(gòu)造函數(shù)錯誤) - IT屋-程序員軟件開發(fā)技術(shù)
mainWindow.loadURL(quot;https://localhost:3000/quot;) show white screen on Electron app(mainWindow.loadURL(https://localhost:3000/) 在 Electron 應(yīng)用程序上顯示白屏)
Electron webContents executeJavaScript : Cannot execute script on second on loadURL(Electron webContents executeJavaScript:無法在第二個 loadURL 上執(zhí)行腳本)
how to use electron browser window inside components in angular-cli?(如何在angular-cli的組件內(nèi)使用電子瀏覽器窗口?)
ElectronJS - sharing redux store between windows?(ElectronJS - 在 Windows 之間共享 redux 存儲?)
How to access camera/webcamera inside electron app?(如何在電子應(yīng)用程序中訪問相機(jī)/網(wǎng)絡(luò)攝像頭?)
主站蜘蛛池模板: 国产精品久久国产精品 | 亚洲精品日韩视频 | 国产一区二区日韩 | 精品视频一区二区三区在线观看 | 亚洲一二三区精品 | 欧美性大战久久久久久久蜜臀 | 欧美激情国产日韩精品一区18 | 一区二区伦理电影 | 在线视频亚洲 | 久久精品一区二区三区四区 | 成人欧美 | 国产精品久久久久久久久久久久久 | 亚洲 欧美 在线 一区 | 91久久久久久 | 亚洲人成在线播放 | 白浆在线| 在线一区二区观看 | 中文字幕日韩欧美 | 国产视频一区二区 | 国产日韩久久 | 久久久精品一区 | 日日干日日色 | 久久久精 | 亚洲国产精品一区 | 九色综合网 | 久久久久久久久久久丰满 | 天堂一区二区三区 | 免费v片在线观看 | 久久99精品久久久久蜜桃tv | 久久成人精品视频 | 日本久久一区二区三区 | 亚洲成人自拍 | 在线国产一区二区 | 日韩免费一区二区 | 欧美激情综合网 | 欧美日韩视频 | 国产小u女发育末成年 | 日韩福利 | 伦理午夜电影免费观看 | 中文字幕av一区 | 亚洲国产69 |