:: Forum >>
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
Sunday, September 3, 2006
Declaring things like this is the same in all languages. regardless if they are scripted or not.
Monday, September 4, 2006
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
Monday, September 4, 2006
Alex (ActiveWidgets)
Monday, September 4, 2006
Thanks Alex.
Exactly what I (obviously :-) ) need.
Karl Thoroddsen
Monday, September 4, 2006
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
Tuesday, September 5, 2006
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
Tuesday, September 5, 2006
This topic is archived.
Back to support forum
Forum search