国产99久久精品_欧美日本韩国一区二区_激情小说综合网_欧美一级二级视频_午夜av电影_日本久久精品视频

最新文章專題視頻專題問答1問答10問答100問答1000問答2000關(guān)鍵字專題1關(guān)鍵字專題50關(guān)鍵字專題500關(guān)鍵字專題1500TAG最新視頻文章推薦1 推薦3 推薦5 推薦7 推薦9 推薦11 推薦13 推薦15 推薦17 推薦19 推薦21 推薦23 推薦25 推薦27 推薦29 推薦31 推薦33 推薦35 推薦37視頻文章20視頻文章30視頻文章40視頻文章50視頻文章60 視頻文章70視頻文章80視頻文章90視頻文章100視頻文章120視頻文章140 視頻2關(guān)鍵字專題關(guān)鍵字專題tag2tag3文章專題文章專題2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章專題3
問答文章1 問答文章501 問答文章1001 問答文章1501 問答文章2001 問答文章2501 問答文章3001 問答文章3501 問答文章4001 問答文章4501 問答文章5001 問答文章5501 問答文章6001 問答文章6501 問答文章7001 問答文章7501 問答文章8001 問答文章8501 問答文章9001 問答文章9501
當(dāng)前位置: 首頁(yè) - 科技 - 知識(shí)百科 - 正文

簡(jiǎn)易Javascript調(diào)試包Debug包_javascript技巧

來源:懂視網(wǎng) 責(zé)編:小采 時(shí)間:2020-11-27 20:55:33
文檔

簡(jiǎn)易Javascript調(diào)試包Debug包_javascript技巧

簡(jiǎn)易Javascript調(diào)試包Debug包_javascript技巧:來看一個(gè)簡(jiǎn)易的 Javascript 調(diào)試包:jscript.debug.js,包含兩個(gè)函數(shù),第一個(gè)用來遍歷對(duì)象的各個(gè)屬性;第二個(gè)是一個(gè)通用的 Debug 函數(shù)(其實(shí) 說對(duì)象'比較精確些',呵呵),用來規(guī)定各種錯(cuò)誤級(jí)別及其各種提示、錯(cuò)誤信息的格式化顯示,還是《Javascr
推薦度:
導(dǎo)讀簡(jiǎn)易Javascript調(diào)試包Debug包_javascript技巧:來看一個(gè)簡(jiǎn)易的 Javascript 調(diào)試包:jscript.debug.js,包含兩個(gè)函數(shù),第一個(gè)用來遍歷對(duì)象的各個(gè)屬性;第二個(gè)是一個(gè)通用的 Debug 函數(shù)(其實(shí) 說對(duì)象'比較精確些',呵呵),用來規(guī)定各種錯(cuò)誤級(jí)別及其各種提示、錯(cuò)誤信息的格式化顯示,還是《Javascr

來看一個(gè)簡(jiǎn)易的 Javascript 調(diào)試包:jscript.debug.js,包含兩個(gè)函數(shù),第一個(gè)用來遍歷對(duì)象的各個(gè)屬性;第二個(gè)是一個(gè)通用的 Debug 函數(shù)(其實(shí) 說‘對(duì)象'比較‘精確些',呵呵),用來規(guī)定各種錯(cuò)誤級(jí)別及其各種提示、錯(cuò)誤信息的格式化顯示,還是《Javascript 實(shí)戰(zhàn)》上面的經(jīng)典例子,先看源碼:

代碼如下:
/**
* jscript.debug package
* This package contains utility functions for helping debug JavaScript.
*
*/
/*命名空間*/
if (typeof jscript == 'undefined') {
jscript = function() { }
}
jscript.debug = function() { }

/**
* This simple function is one of the handiest: pass it an object, and it
* will pop an alert() listing all the properties of the object and their
* values.(這個(gè)函數(shù)用來遍歷對(duì)象的屬性及其相應(yīng)的值,并顯示出來)
*
* @param inObj The object to display properties of.
*/
jscript.debug.enumProps = function(inObj) {

var props = "";
var i;
for (i in inObj) {
props += i + " = " + inObj[i] + "\n";
}
alert(props);

} // End enumProps().

/**
* This is a very simple logger that sends all log messages to a specified
* DIV.(這是一個(gè)簡(jiǎn)單的 debug 日志記錄系統(tǒng))
*/
jscript.debug.DivLogger = function() {

/**
* The following are faux constants that define the various levels a log
* instance can be set to output.(下面的常量用來定義錯(cuò)誤級(jí)別)
*/
this.LEVEL_TRACE = 1;
this.LEVEL_DEBUG = 2;
this.LEVEL_INFO = 3;
this.LEVEL_WARN = 4;
this.LEVEL_ERROR = 5;
this.LEVEL_FATAL = 6;

/**
* These are the font colors for each logging level.(定義各種錯(cuò)誤的顯示顏色)
*/
this.LEVEL_TRACE_COLOR = "a0a000";
this.LEVEL_DEBUG_COLOR = "64c864";
this.LEVEL_INFO_COLOR = "000000";
this.LEVEL_WARN_COLOR = "0000ff";
this.LEVEL_ERROR_COLOR = "ff8c00";
this.LEVEL_FATAL_COLOR = "ff0000";

/**
* logLevel determines the minimum message level the instance will show.(需要顯示的最小錯(cuò)誤級(jí)別,默認(rèn)為 3)
*/
this.logLevel = 3;

/**
* targetDIV is the DIV object to output to.
*/
this.targetDiv = null;

/**
* This function is used to set the minimum level a log instance will show.
*(在這里定義需要顯示的最小錯(cuò)誤級(jí)別)
* @param inLevel One of the level constants. Any message at this level
* or a higher level will be displayed, others will not.
*/
this.setLevel = function(inLevel) {

this.logLevel = inLevel;

} // End setLevel().

/**
* This function is used to set the target DIV that all messages are
* written to. Note that when you call this, the DIV's existing contents
* are cleared out.(設(shè)置信息顯示的 DIV,調(diào)用此函數(shù)的時(shí)候,原有的信息將被清除)
*
* @param inTargetDiv The DIV object that all messages are written to.
*/
this.setTargetDiv = function(inTargetDiv) {

this.targetDiv = inTargetDiv;
this.targetDiv.innerHTML = "";

} // End setTargetDiv().

/**
* This function is called to determine if a particular message meets or
* exceeds the current level of the log instance and should therefore be
* logged.(此函數(shù)用來判定現(xiàn)有的錯(cuò)誤級(jí)別是否應(yīng)該被顯示)
*
* @param inLevel The level of the message being checked.
*/
this.shouldBeLogged = function(inLevel) {

if (inLevel >= this.logLevel) {
return true;
} else {
return false;
}

} // End shouldBeLogged().

/**
* This function logs messages at TRACE level.
*(格式化顯示 TRACE 的錯(cuò)誤級(jí)別信息,往依此類推)
* @param inMessage The message to log.
*/
this.trace = function(inMessage) {

if (this.shouldBeLogged(this.LEVEL_TRACE) && this.targetDiv) {
this.targetDiv.innerHTML +=
"" +
"[TRACE] " + inMessage + "";
}

} // End trace().

/**
* This function logs messages at DEBUG level.
*
* @param inMessage The message to log.
*/
this.debug = function(inMessage) {

if (this.shouldBeLogged(this.LEVEL_DEBUG) && this.targetDiv) {
this.targetDiv.innerHTML +=
"" +
"[DEBUG] " + inMessage + "";
}

} // End debug().

/**
* This function logs messages at INFO level.
*
* @param inMessage The message to log.
*/
this.info = function(inMessage) {

if (this.shouldBeLogged(this.LEVEL_INFO) && this.targetDiv) {
this.targetDiv.innerHTML +=
"" +
"[INFO] " + inMessage + "";
}

} // End info().

/**
* This function logs messages at WARN level.
*
* @param inMessage The message to log.
*/
this.warn = function(inMessage) {

if (this.shouldBeLogged(this.LEVEL_WARN) && this.targetDiv) {
this.targetDiv.innerHTML +=
"" +
"[WARN] " + inMessage + "";
}

} // End warn().

/**
* This function logs messages at ERROR level.
*
* @param inMessage The message to log.
*/
this.error = function(inMessage) {

if (this.shouldBeLogged(this.LEVEL_ERROR) && this.targetDiv) {
this.targetDiv.innerHTML +=
"" +
"[ERROR] " + inMessage + "";
}

} // End error().

/**
* This function logs messages at FATAL level.
*
* @param inMessage The message to log.
*/
this.fatal = function(inMessage) {

if (this.shouldBeLogged(this.LEVEL_FATAL) && this.targetDiv) {
this.targetDiv.innerHTML +=
"" +
"[FATAL] " + inMessage + "";
}

} // End fatal().

} // End DivLogger().

源碼看完后,我們來測(cè)試一下這個(gè)“小包”,來看下面的測(cè)試源碼:

代碼如下:

onClick="jscript.debug.enumProps(document.getElementById('enumPropsLink'));">
enumProps()-Shows all the properties of this link(顯示此鏈接標(biāo)簽對(duì)象的所有屬性和值)

Log message will appear here

聲明:本網(wǎng)頁(yè)內(nèi)容旨在傳播知識(shí),若有侵權(quán)等問題請(qǐng)及時(shí)與本網(wǎng)聯(lián)系,我們將在第一時(shí)間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

文檔

簡(jiǎn)易Javascript調(diào)試包Debug包_javascript技巧

簡(jiǎn)易Javascript調(diào)試包Debug包_javascript技巧:來看一個(gè)簡(jiǎn)易的 Javascript 調(diào)試包:jscript.debug.js,包含兩個(gè)函數(shù),第一個(gè)用來遍歷對(duì)象的各個(gè)屬性;第二個(gè)是一個(gè)通用的 Debug 函數(shù)(其實(shí) 說對(duì)象'比較精確些',呵呵),用來規(guī)定各種錯(cuò)誤級(jí)別及其各種提示、錯(cuò)誤信息的格式化顯示,還是《Javascr
推薦度:
  • 熱門焦點(diǎn)

最新推薦

猜你喜歡

熱門推薦

專題
Top
主站蜘蛛池模板: 一区二区三区欧美日韩 | 亚洲v日韩v欧美在线观看 | 国产精品视频一区二区噜噜 | 久久国产精品自由自在 | 国产免费一区二区三区 | 大陆一级毛片 | 国产99久久九九精品免费 | 亚洲一区二区三区在线播放 | 欧美日本韩国一区二区 | 影音先锋亚洲综合小说在线 | 欧美阿v高清资源在线 | 亚洲三级在线播放 | 日韩欧美国产中文字幕 | 么公的又大又深又硬想要 | 一级毛片一级毛片一级毛片 | 一本久久精品一区二区 | 全免费午夜一级毛片一级毛 | 岛国大片在线观看 | 午夜三级视频 | 伊人久久大香线蕉综合爱婷婷 | 91精品国产综合久久久久久 | 成人一级片在线观看 | 久久国产精品成人免费 | 91大神在线观看精品一区 | 香蕉依人 | 中文字幕精品一区二区精品 | 欧美日韩在线观看一区二区 | 亚洲欧美激情在线 | 亚洲精品在线免费观看视频 | 国产高清在线免费视频 | 啪啪国产| 亚洲一区二区精品视频 | 日韩在线国产 | 欧美日韩综合视频 | 国产成人欧美一区二区三区的 | 在线视频一二三区2021不卡 | 久久精品男人影院 | 日韩精品一区二区三区不卡 | 精品一区二区三 | 欧美日韩亚洲一区二区三区在线观看 | 久久国产欧美日韩高清专区 |