Recently, looking at the various components written by a company's JS Daniel, we have to start with the easy process. I read a JS debugging tool class and found the problem during the Demo writing process. As a result, I searched for some information on the Internet and wrote a JS debugging tool by myself.
Recently, looking at the various components written by a company's JS Daniel, we have to start with the easy process.
I read a JS debugging tool class and found the problem during the Demo writing process.
As a result, I searched for some information on the Internet and wrote a JS debugging tool by myself.
Actual needs
JS debugging is not convenient. alert is unfriendly and time-consuming.
I learned that the browser has a built-in Console object (not in JavaScript), but different browsers support different methods.
Therefore, it is necessary to encapsulate the Console method to adapt to different browsers.
Tool JS source code
/*** FansUnion-JS-Log1.0 ** QQ: 240370818 * Email: LeiWen@FansUnion.cn * Date: 2013.12.9 * Copyright 2013-2014, leiwen * // debug tool class var LogUtil = (function (win, doc) {var LogUtil = win. logUtil | {}; // you can use LogUtil by default. enable = true; // The following four methods, IE/Firefox/Chrome/Opera Support // console-info message LogUtil.info = function (msg) {LogUtil. doLog (msg, 'info') ;}; // console-error LogUtil. error = function (msg) {LogUtil. doLog (msg, 'error') ;}; // console-warn warns LogUtil. warn = function (msg) {LogUtil. doLog (msg, 'warn') ;}; // console-log, can be displayed (in Firefox, All, error-warning-message-debugging information is not displayed) logUtil. log = function (msg) {LogUtil. doLog (msg, 'log') ;}; // The method supported by one or more browsers may not be supported by some browsers. If not, no error is reported, no prompt/debug LogUtil. debug = function (msg) {LogUtil. doLog (msg, 'debug') ;}; // you can call a specific LogUtil method in a browser based on your needs. doLog = function (msg, level) {var useable = LogUtil. isUseable (level); // available to call if (useable) {win. console [level] (msg) ;}; // whether the console method is available, the methods supported by IE/Firefox/Chorome/Opera are different // log info warn error assert dir clear profile profileEnd on the IE console // log info warn error debug exception assert dir dirxml trace on the Firebug Console // group groupEnd groupCollapsed time timeEnd profile profileEnd count clear table policyfirebug firebug // Chrom console profiles memory debug error info log warn dir dirxml trace assert count markTimeline/profile profileEnd time timeEnd group groupCollapsed groupEnd // Opera console time timeEnd trace profile profileEnd debug log info warn error assert dir // dirxml group groupCollapsed groupEnd count table // determine whether debugging of a certain level is available (level = error, warn, info, debug, etc.) LogUtil. isUseable = function (level) {var useable = LogUtil. enable & win. console & win. console [level]; return useable;} return LogUtil;}) (window, document );
Test example