Last time I wrote an article discussing "The difference between two implementations of JavaScript class definition prototype methods". After research, we found that except for the different initialization methods of the methods, we found no other differences in principle, which means that no matter which method is used, it is the same. However, I later discovered that when setting breakpoints for debugging the prototype method in VS.NET, there was a big difference between the two definition methods.
First look at the following code example: 1 ToolBar.prototype.Dispose = function()
2 {
3 var elmt = this.GetElement(); ***
4 select elmt.onsstart = '';
5 elmt.oncontentmenu = '';
6 elmt.clearAttributes();
7 // todo
8 }
My code went wrong here. The debugger VS.NET stopped the code execution cursor at line 4 and wouldn't let me drag it up. I think if I can drag it up, I can step into the following this.GetElement() method. Since it can't be dragged, I will set a breakpoint on line 3. After setting it up, attach the debugger. Why can't it stop at line 3 of code? Looking at the debugger, the breakpoint is automatically set to the first line of code by VS.NET, and the entire ToolBar.prototype.Dispose method is highlighted@_@. So I wanted to manually set the breakpoint to line 3, but I couldn't succeed. Once a breakpoint is set on line 3, it will automatically jump to line 1, but it can be set on lines of code after line 3, such as 4, 5, or 6. There is an ugly solution here, which is to add a useless statement before the 3rd line of code (simple var definition of variables will not work, at least var a=1;), and change the current 3rd line to the 4th line. That's it. This bug is really baffling.
Today I discovered that this problem can be solved by changing ToolBar.prototype.Dispose = function() to: function ToolBar.prototype.Dispose()! How strange! ~ 1function ToolBar.prototype.Dispose()
2{
3 var elmt = this.GetElement(); ***
4 elmt.onselectstart = '';
5 elmt.oncontentmenu = ' ';
6 elmt.clearAttributes();
7 // todo
8}
With the above method, you can set breakpoint on line 3 at will. This problem exists in both VS.NET 2003 and VS.NET 2005 beta1. Does anyone have time to get VS.NET 2005 beta2 to see if this problem still exists?