Javascript debug 库

本文介绍了一套用于辅助编程调试的工具集,包括设置调试模式、日志输出、断言检查及类型验证等功能。通过这些工具可以有效提升开发过程中的调试效率。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

编程好帮手,加载后利于调试

var _DEBUG_=0;
function setDebug(v){
if(typeof(v)!="boolean"){
console.log("Error: must use boolean value for function setDebug()");
}else{
_DEBUG_=v;
}
}
function log(a){
if(_DEBUG_)console.log(a);
}
function assert(condition,errmsg){
if (!condition) {
      console.log("AssertError:"+errmsg);
   }
}
function assertType(com,expectType){
if(!typeOf(com)==expectType){
console.log("AssertError:"+com +"is not type of "+expectType);
}
}
function showAllType(){
console.log("All Types:boolean, undefined, number, string, object, function ");
//number string can be judge with isNaN()
}
function inspect(obj) {
var message = 'Object possesses these properties:\n';
if (obj) {
for ( var i in obj) {
if ((obj[i] instanceof Function) || (obj[i] == null)
|| (i.toUpperCase() == i))
continue;
message += i + ', ';
}
message = message.substr(0, message.length - 2);
} else
message = 'Object is null';
log(message);
}
function inspectValues(obj) {
var message = '';
if (obj)
for ( var i in obj) {
if ((obj[i] instanceof Function) || (obj[i] == null)
|| (i.toUpperCase() == i))
continue;
message += i + ': ' + obj[i] + '\n';
}
else
message = 'Object is null';
log(message);
}


// 还有一个函数,自己无法理解,试用也不成功,记录在这里,以便将来研究
// // log (message)
// Logs a message. Every second, all logged
// messages are displayed
// in an alert box. This saves you from having to hit
// Return a ton of times as your script executes.

function log(message) {
if (!_log_timeout)
_log_timeout = window.setTimeout(dump_log, 1000);
_log_messages.push(message);
function dump_log() {
var message = '';
for (var i = 0; i < _log_messages.length; i++)
message += _log_messages[i] + '\n';
alert(message);
_log_timeout = null;
delete _log_messages;
_log_messages = new Array();
}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值