Welcome to WebmasterWorld Guest from 174.129.151.95

Forum Moderators: open

Message Too Old, No Replies

Javascript "var" crashes NS4

var with more than one variable brings down app

   
7:00 pm on Jul 11, 2002 (gmt 0)

WebmasterWorld Administrator ergophobe is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



I have a couple of "var" declarations with multiple variables per line in a JS file, as in

var lmargin, tmargin, winHeight, winWidth, params

This immediately crashes NS4, but works fine in everything else. I thought this was acceptable and a way to save a little bandwidth, but I guess not. If I change it to

var lmargin
var rmargin

It works just fine. It took me so long to figure it out I just had to share!

Tom

6:11 pm on Jul 12, 2002 (gmt 0)

10+ Year Member



I've never had a problem with that. Even NS2 never had difficulty with var, although it had difficulty with just about anything else.

On the other hand, assigning a value to an uninitialized variable automatically creates a top-level variable (the nearest thing JavaScript can get to a global variable), so var is redundant outside of a function or control loop body. Even within loops and functions, you can get away without using var, if you know for certain you can keep track of all the variables in all of your scripts on that page.

10:39 pm on Jul 12, 2002 (gmt 0)

WebmasterWorld Administrator ergophobe is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



Actually, the var declaration was in a function and was intended to keep the scope local. What's weird is that it doesn't create errors on the page or anything like that, it literally crashes the application and it has to be restarted, and that's true even with NS on Irix.

Once I put one variable per var statement, no problems.

7:18 am on Jul 13, 2002 (gmt 0)

10+ Year Member



I always initialize and assign my variables in one go -- JavaScript is designed to do that, and it saves a couple of bytes here and there:

var browser='Navigator 4', javaScriptSupport='adequate', cssSupport='poor', domImplementation='catastrophic';

I can't remember if I've ever done that inside a function body. It's a strange bug, and I've never seen it documented anywhere...

2:06 pm on Jul 13, 2002 (gmt 0)

WebmasterWorld Administrator ergophobe is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



Thanks. I'm not a JS person at all (though I knew I *should* do that in JS). Anyway, my JS needs a lot of optimization, but I was just trying to get it from crashing NS first. This is NS4.5, byt hte way. I haven't tested it with other 4.x versions.

Cheers,

Tom