homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

Javascript "var" crashes NS4
var with more than one variable brings down app

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

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!




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

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)

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)

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)

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.



Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved