| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Hi fellow coders
I would like to share a little technique I've developed that helps me develop software in JavaScript. Being a VB programmer from way back, I have grown thoroughly spoiled when it comes to IntelliSense and the ability to step through a program's execution at runtime. Such an advantage is not available to me in JavaScript programming, especially in a browser environment where script debugging is disabled (often a required condition at business sites. So I do the next best thing: I use the alert() function throughout my code. However, doing so ends up either littering my code with gazillions of commented-out alert() statements, or it requires me to keep inserting them. Additionally, it can be hard to find an alert's home in the code when it has so many look-alikes. My first approach to this problem was to include line numbers in my alerts. For example, if the code line 1100 sets a value that I want to test, I might follow it up with an alert that looks like this: PHP Code:
In this case, the alert() will not only inform me of the value in some hidden control, it will also tell me where to look in the code in case I need to check my logic any further. But my code was getting cluttered, so I decided to encapsulate the alert() function into something of my own that would manage the process more effectively. PHP Code:
Code:
<%--values to use: blank for none, 0 for all, other values for specific--%>
<input type="hidden" id="hdnDebug" value=""/> <%--next unused value is 10--%>
At design time, I might set it to "" (as in this case), which is my way of telling my app to ignore all alerts. Now let's say that I'm testing some complex process in my code where I want alerts in several different places. What I'll do is assign a number, say 5, as the RestrictionCode for all of these alerts, and only these. PHP Code:
Above is an example where I gather up data for a rather verbose message that I want to raise at line 118 in code. I set the RestrictionCode parameter to 5, store that value in hdnDebug, and run the app. Any DebugAlert() command that doesn't have a RestrictionCode of 5 will be ignored, and the messages of interest will pop into view when needed. Conversely, if I want to go all-out debug crazy, all I have to to is put "0" into the hdnDebug control, and every DebugAlert() command will cause an alert() to occur. Finally, as you may have guessed, it might be tough to keep track of the RestrictionCode values in use. In the example above, my HTML has a comment telling me about the next unused value, which I simply update as needed. Code:
<%--next unused value is 10--%> I could also construct an extended comment that specifies what each RestrictionCode is for: Code:
<%--values to use: blank for none, 0 for all, other values for specific--%>
<input type="hidden" id="hdnDebug" value=""/> <%--next unused value is 10--%>
<%--Codes in use:
1 - Testing login process
2 - Comparing string values returned by Employee Data
3 - Testing SQL data source behavior
4 - For comparing visual feedback in UI to underlying logical values
in connection with the UpdateFinancials() process--%>
Oh, and since DebugAlert() is a function I declare on my web page, I get to use IntelliSense while writing calls to it. This whole business evolved as I taught myself to develop in JavaScript and wanted it to behave more like VB. I'm sure that the evolution will continue, but I thought some of you might find it useful in the mean time. Enjoy! - Matt Last edited by mattgb1 : January 11th, 2008 at 12:59 PM. Reason: thought of something else |
![]() |
| Viewing: ASP Free Forums > Programming > Code Bank > Making Javascript act more like VB in the .net IDE |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|