Posts in "Javascript" category

Dynamic loading of Javascript

When programming desktop applications I’ve always been a supporter of lazy loading of objects but I’ve never given this much thought when creating websites. Until now. (more…)

Debugging JavaScript with MS Visual Studio

There’s an ancient fable that tells of a frog that falls into a pail of milk. Unable to scramble out, the creature trashes around, seemingly drowning. Eventually however, his frantic struggles turn the milk into butter – and he hops away.

Until now, that fable has been a good metaphor of my struggle with the seven headed beast called JavaScript. I’ve written my lines of code, gotten inane script errors from IE, tried, failed and tried again. Also known, and forever hated, as trial and error programming.

Of course, jolly, happy and cheerful memories from BW2 (before Web 2.0) – when I coded Java all day and all night, with the best tools of the trade – didn’t help much either.

So, I felt like the frog. But that was until I discovered that I could debug javascript with Visual Studio. Yes, that’s right – actual debugging in javascript.

I’m not saying this is news, I’m just saying it’s news to me (and probably to a couple of others as well – those weird looking geeks in the corner, there. See them?). And, yes, I am aware of Venkman.

If you’re not a .net developer, it isn’t in-your-face obvious how you do this, so often you rely on someone just showing it to you. I’ve done some screenshots for you guys and gals.

How to do it!

Just visit the webpage you want to debug with IE. Then fire up Visual Studio, and select Tools -> Attach to Process…

Attach to process Then you find the iexplore.exe instance you want. Click “Attach”.

Attach to process And voilá! You’re in a full-featured debugger; a script explorer, code-view where you can set breakpoints etc. and a panel where you can add watches and view values of locals.

Click for larger version This is brilliant. Now this JavaScript programming should feel less like thrashing in a pail of milk, and more like enjoying a cup of hot chocolate.