具有正确行号的控制台.log的正确包装器?
2022-08-30 02:01:18
我现在正在开发一个应用程序,并放置一个全局开关。我想包装以方便使用。isDebug
console.log
//isDebug controls the entire site.
var isDebug = true;
//debug.js
function debug(msg, level){
var Global = this;
if(!(Global.isDebug && Global.console && Global.console.log)){
return;
}
level = level||'info';
Global.console.log(level + ': '+ msg);
}
//main.js
debug('Here is a msg.');
然后我在Firefox控制台中得到这个结果。
info: Here is a msg. debug.js (line 8)
如果我想用被调用的行号记录,比如?debug()
info: Here is a msg. main.js (line 2)