3.0 beta 2

Pitfalls with Javascript

Having spent nearly 3 days trying to understand why a Grid wasn't updating its data I finally stumbled on the solution. I'm probably not exaggerating when I say that this is on of the most dangerous issues with using a scripting language like Javascript:

You can declare a variable in the global scope and another with the same name inside a function. You think you are talking to a single Grid object when you are infact talking to two in different parts of the code.

Nothing will break, just nothing will work.

So if you are having problems with your UI element, Grid or Table not responding correctly then take a quick peek at the declaration.

Karl Thoroddsen
September 3,
Declaring things like this is the same in all languages. regardless if they are scripted or not.
September 4,
That is true but if you are used to programming in true OO languages then the issue of double declarations really doesn't come up.

In that regard JavaScript is essentially like C with the added bonus/danger of generic positioning of variable declarations.

Karl Thoroddsen
September 4,
In some cases using js syntax checkers like JSLint helps a lot -


Alex (ActiveWidgets)
September 4,
Thanks Alex.

Exactly what I (obviously :-) ) need.
Karl Thoroddsen
September 4,
even in OO languages you get this double declatation but I understand what you mean, it needs strict variable declaration.

what I do is always declare variables used in the JS function to try and avoid these issues as you can see you are using somthing local. or start naming your globals to avoid it gobjGrid for instance
September 5,
Yes I try to use "its" as a prefix for global variables and "the" for local ones. The problem is the same as with C and other scripting languages that, as you probably know, it is too easy to break the rules.

Karl Thoroddsen
September 5,

This topic is archived.

See also:

Back to support forum


Version 2

Looking for AW 2.6 ?
The old site is here.