Please login or register. Welcome to the Studio, guest!


Quick Links:


newBookmarkLockedFalling

Moose

Moose Avatar

****
Senior Member

449


August 2005
What are your general debugging methods for coding JavaScript? I generally now only have to debug for larger scripts. Anyway if I write a script and see it is not working I first check the JS console in FF, which I think is personally a great debugger. Next if the code still isn't working, I use alert on some of my variables to discover their values and look for possible screw ups. I also alert with conditionals something like:

if(blah.innerHTML.match(/whatever/)){
alert('Yes!');
}

And if I don't get an alert I know there is probably something wrong with the regular expression and if not that I screwed up the conditional or somewhere around there.

What methods do you use? :)

Greg says:
Coding music...
Greg says:
Hmm...
Greg says:
I wouldn't rule it out. :P
Chris 3.0 [New features? Yes.] says:
:P
Greg says:
If you think about machine code it's a bunch of 1s and 0s
Chris 3.0 [New features? Yes.] says:
Anything is possible.
Greg says:
Yeah try to code Metallica
Chris 3.0 [New features? Yes.] says:
:P Yeah, I'll get right on that... right after I learn to fly.

Scorpian

Scorpian Avatar

******
[ Bracket Admin ]

2,457


April 2006
I use the RegExp tester for FireFox to make sure any RegExp string I write will actually work. I'm not that good at RegExp :-/.
wat

Chris

Chris Avatar

******
Head Coder

19,519


June 2005
JS console in FF. If its an error in IE, I've learned how to deal with those, as they're usually "Runtime Errors" which come from using certain methods of innerHTML on a DOM created object.

As you said, next step is the RegExp method of alert. I had a problem with that yesterday actually and couldn't figure it out. Came down to the fact that .+? doesn't match line breaks.... =/

crazynarutard

crazynarutard Avatar

*****
Senior Studio Member

1,470


August 2005
- Bugzilla for Mozilla Firefox
- Alerting variables to see if they have been set etc.



Chris

Chris Avatar

******
Head Coder

19,519


June 2005
I just remembered another one.... Cali taught me this. Since IE and FF handle the source differently, you can view what's be interpreted line for line with typing this in your URL window and hitting enter.

javascript:"<xmp>"+document.body.innerHTML+"</xmp>";

But if you have FF, get the "Web Developer Toolbar"... View Source menu has an option to "View Generated Source" :D

Andrew McGivery

Andrew McGivery Avatar
Formerly Fredy

******
Legendary Studio Member

Male
5,742


September 2005
Cali had many cool things to show off. i learn a few things form him jsut by reading his posts.
k

Virtuoso

Virtuoso Avatar

****
Senior Member

271


May 2006
Debugger codes help, and alerts.

also, on a side note, .+? isn't grabbign commas. Grar.

crazynarutard

crazynarutard Avatar

*****
Senior Studio Member

1,470


August 2005
virtuoso said:
Debugger codes help, and alerts.

also, on a side note, .+? isn't grabbign commas. Grar.

yes it does.

Virtuoso

Virtuoso Avatar

****
Senior Member

271


May 2006
:-/ Didn't for me. Found a way to work around it though.

Neways. Firebug. =D

Nate

Nate Avatar

**
Official Member

85


July 2007
virtuoso said:
:-/ Didn't for me. Found a way to work around it though.

Neways. Firebug. =D
Using a "," works :P :

if(td[2].innerHTML.match(/hey,/i)){

Chris

Chris Avatar

******
Head Coder

19,519


June 2005
javascript:alert(/.+?/.test(",,,,"));void(0);

It does work. =/

Nate

Nate Avatar

**
Official Member

85


July 2007
Something I just found out:


function omg(){
alert('omg');
}


javascript: alert(omg);
Would alert


function omg(){
alert('omg');
}
:)

Chris

Chris Avatar

******
Head Coder

19,519


June 2005
Well yeah, because you're alerting the value of the variable "omg", which is actually that function. :P

var omg = function(){
alert("omg");
}

That's basically how its interpreted (correct me if I'm wrong.)

Virtuoso

Virtuoso Avatar

****
Senior Member

271


May 2006
nate said:
virtuoso said:
:-/ Didn't for me. Found a way to work around it though.

Neways. Firebug. =D
Using a "," works :P :

if(td[2].innerHTML.match(/hey,/i)){


Not when your working with checking wether there is a comma or not. ;)

Sasuke

Sasuke Avatar

****
Senior Member

418


August 2005
Stream through the code lots of times :P

newBookmarkLockedFalling