goodluck 发表于 2010-2-20 14:33:55

Java应用:JavaScript写Log类的具体实现

<p >由于现在jscript 编写方式比以外负责很多,很多时候都比较难以调试。 为了方便日常程序中的调试,摆弄些下面写Log Class 将需要内容记录下来。<p ><p >下面就是具体源代码,此Class 只能在 IE浏览器使用。<p ><p ><ccid_nobr><table width="400" border="1" cellspacing="0" cellpadding="2"bordercolorlight = "black" bordercolordark = "#FFFFFF" align="center"><tr><td bgcolor="e6e6e6" class="code" ><pre><ccid_code>1 LogClass.prototype = { 2          3         initialize : function(){ 4            5             try{ 6                  7               this._fso = &quot;&quot;;//File 操作对象 89               this._folderspec = &quot;&quot;;// 类 fileclass 处理路径10 11               this._fso = new ActiveXObject(&quot;Scripting.FileSystemObject&quot;);                   // 建立 ActiveXObject 对象12               13               this._objDate = new Date();14 15               this._DateString =this._objDate.format(&quot;yyMMdd&quot;);16 17               this._DateString = &quot;c:\\&quot; + this._DateString + &quot;.log&quot; ;18 19               this._folderspec = this._DateString;20               21 22             }catch(e){23               24               alert(&quot;file Class initialize Error: &quot;+ e.number +&quot; &quot;+ e.description);25 26             }27 28         },29         TRACE : function(Content){30             31             try{32 33               this.OpenTextFile(8,true);34 35               _objDate = new Date();36               37               _dateString = _objDate.format(&quot;yyyy-MM-dd hh:mm:ss&quot;);38 39               this._otf.WriteLine(_dateString+&quot;||&quot;+Content);40 41               this._otf.close();42 43             }catch(e){44 45               this._otf.Close();46               47               alert(&quot;file Class TRACE Error: &quot;+ e.number +&quot; &quot;+ e.description);48             49             }50         51         },52         OpenTextFile : function(IOmode,format){53 54             try{55               56               this._otf = this._fso.OpenTextFile(this._folderspec,IOmode,true,format);57 58             }catch(e){59 60               this._otf.Close();61 62               alert(&quot;file Class OpenTextFile Error: &quot;+ e.number +&quot; &quot;+ e.description);63 64             }65         66         }67 68 };</ccid_code></pre></td></tr></table></ccid_nobr><br><p ><p ><P align=right></P><p align="center"></p></p>
页: [1]
查看完整版本: Java应用:JavaScript写Log类的具体实现