2012-04-10 22 views

回答

4

号这就是为什么你不应该开发/调试过程中使用minified的代码。

+0

而且嘿,那将是很好,如果萤火虫&CO有一个选项可以自动美化minified的代码*和*映射错误位置等到美化代码中的正确行。 – ThiefMaster 2012-04-10 07:46:34

+2

我不会认为这是在开发过程中。我和这里的提问者有完全相同的问题。我的代码工作得很好,直到它被缩小。 – 2012-11-28 02:17:04

1

您可以美化缩小的代码。在铬检查员,它是{}按钮,被称为“漂亮的打印”。

但是,美化这个代码并不意味着它会尊重你的原始代码。

因此,我会说什么ThiefMaster说:在开发/调试过程中不要使用缩小的代码。

1

您希望调试缩小脚本的一个原因是如果您使用闭包编译器对其进行优化并且优化过程导致了错误。 对于在堆栈跟踪,你可以做这样的事情供应柱器(Chrome,IE)浏览器:

/*@const*/ //for closure-compiler 
DEBUG=2 // 0=off, 1=msg:file:line:column, 2=msg:stack-trace 
if(DEBUG){ 

/*@const @constructor*/ 
Object.defineProperty(window,'__stack__',{get:function(){ 
    try{_ფ_()}catch(e){return e.stack.split(":")} 
}}) 

/*@const @constructor*/ 
Object.defineProperty(window,'__file__',{get:function(){ 
    var s=__stack__,l=s.length 
    return (isNaN(s[l-2]))?s[l-2]:s[l-3] 
}}) 

/*@const @constructor*/ 
Object.defineProperty(window,'__line__',{get:function(){ 
    var s=__stack__,l=s.length 
    return (isNaN(s[l-2]))?s[l-1]:s[l-2] 
}}) 

/*@const @constructor*/ 
Object.defineProperty(window,'__col__',{get:function(){ 
    var s=__stack__,l=s.length 
    return (isNaN(s[l-2]))?"NA":s[l-1] 
}}) 

/*@const @constructor*/ 
Object.defineProperty(window,'LOG',{ 
    get:function(){return out}, 
    set:function(msg){if(DEBUG>1)out=msg+"\t-\t"+__stack__ 
     else out=msg+" in file:"+__file__+" @ Line:"+__line__+", Column:"+__col__ 
     console.log(out)} 
}) 
}//end if(DEBUG) 

用法:LOG="my message"写“我的信息”与行号和文件到控制台或拿到最后一个日志alert(LOG)

你可以得到更多的进入杂草与V8(铬,Node.js的)

/*@const @constructor*/ Object.defineProperty(this,'__stack',{get:function(){var o=Error['prepareStackTrace'],e=new Error,s;Error['prepareStackTrace']=function(_,s){return s},Error['captureStackTrace'](e,arguments['callee']),s=e['stack'],Error['prepareStackTrace']=o;return s}}) 

/*@const @constructor*/ Object.defineProperty(this,'__col__',{get:function(){return __stack[1]['getColumnNumber']()}}) 
/*@const @constructor*/ Object.defineProperty(this,'__eval_orig__',{get:function(){return __stack[1]['getEvalOrigin']()}}) 
/*@const @constructor*/ Object.defineProperty(this,'__file__',{get:function(){return __stack[1]['getFileName']()}}) 
/*@const @constructor*/ Object.defineProperty(this,'__func__',{get:function(){return __stack[1]['getFunctionName']()}}) 
/*@const @constructor*/ Object.defineProperty(this,'__function__',{get:function(){return __stack[1]['getFunction']()}}) 
/*@const @constructor*/ Object.defineProperty(this,'__is_constructor__',{get:function(){return __stack[1]['isConstructor']()}}) 
/*@const @constructor*/ Object.defineProperty(this,'__is_eval__',{get:function(){return __stack[1]['isEval']()}}) 
/*@const @constructor*/ Object.defineProperty(this,'__is_native__',{get:function(){return __stack[1]['isNative']()}}) 
/*@const @constructor*/ Object.defineProperty(this,'__is_top_level__',{get:function(){return __stack[1]['isTopLevel']()}}) 
/*@const @constructor*/ Object.defineProperty(this,'__line__',{get:function(){return __stack[1]['getLineNumber']()}}) 
/*@const @constructor*/ Object.defineProperty(this,'__method__',{get:function(){return __stack[1]['getMethodName']()}}) 
/*@const @constructor*/ Object.defineProperty(this,'__this__',{get:function(){return __stack[1]['getThis']()}}) 
/*@const @constructor*/ Object.defineProperty(this,'__type__',{get:function(){return __stack[1]['getTypeName']()}}) 
相关问题