2012-04-10 60 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']()}})