当前位置: 首页 > 图文教程 > 网络编程 > Javascript > 原型方法的不同写法居然会影响调试的解决方法

Javascript
form中限制文本字节数js代码
use jscript with List Proxy Server Information
use jscript List Installed Software
List Installed Software Features
List Information About the Binary Files Used by an Application
List the Codec Files on a Computer
List the UTC Time on a Computer
List Installed Hot Fixes
excel操作之Add Data to a Spreadsheet Cell
Add Formatted Data to a Spreadsheet
Apply an AutoFormat to an Excel Spreadsheet
JavaScript语法着色引擎(demo及打包文件下载)
类之Prototype.js学习
一款JavaScript压缩工具:X2JSCompactor
iis6+javascript Add an Extension File
jscript之Open an Excel Spreadsheet
jscript之Read an Excel Spreadsheet
jscript之List Excel Color Values
去除图像或链接黑眼圈的两种方法总结
Add a Formatted Table to a Word Document

Javascript 中的 原型方法的不同写法居然会影响调试的解决方法


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-12   浏览: 169 ::
收藏到网摘: n/a

上次我写过一篇文章,讨论"JavaScript类定义原型方法的两种实现的区别"。研究后发现除了方法的初始化方式不同外,没有发现别的原则上的却别,也就是说用哪种方式都一样。可是后来发现在VS.NET中给原型方法设置断点来调试时,两种定义方式却出现了很大的差别。
先看如下代码示例: 1 ToolBar.prototype.Dispose = function()
2 {
3 var elmt = this.GetElement(); ***
4 elmt.onselectstart = '';
5 elmt.oncontentmenu = '';
6 elmt.clearAttributes();
7 // todo
8 }
我的代码运行在这里出了错,调试器VS.NET把代码执行光标停在了第4行,而且不让我拖拽上去。我想如果能拖上去就可以step into的跟踪以下this.GetElement()方法嘛。既然不能拖,我就在第3行设一个breakpoint呗,设好后attach调试器,怎么不能停到代码行3的地方呢?在调试器一看,断点被VS.NET自动设到第一行代码上去了,并且整个的ToolBar.prototype.Dispose方法都是被highlight了@_@。于是我想手动把breakpoint再设置到第3行代马上去,却怎么也不能成功。一在第3行上设置breakpoint就会自动跳到第1行,但可以在第3行以后的代码行上设,比如4,5,6向后都可以。这里有个ugly的解决方法,就是在第3行代码前一句无用的语句(简单的var定义变量是不行的,至少要var a=1;),把现在的第3行变成第4行就可以了。这种bug真是让人莫名其妙哈。
今天发现可以这么来解决这个问题,把ToolBar.prototype.Dispose = function()改成:function ToolBar.prototype.Dispose()就行了!真是怪!~ 1function ToolBar.prototype.Dispose()
2{
3 var elmt = this.GetElement(); ***
4 elmt.onselectstart = '';
5 elmt.oncontentmenu = '';
6 elmt.clearAttributes();
7 // todo
8}
上面这个方法,就可以随意的在第3行上设置breakpoint。这个问题同时存在于VS.NET 2003和VS.NET 2005 beta1中。谁有空拿VS.NET 2005 beta2看看这个问题还有没有。