Doug Wright wrote:
You're complaining about the amount of code, but want a lengthier
version (with comments)?
Yes, I do. Quantity is not quality. If a greater quantity of code
also increases the overall quality, I can accept the former.
The original code is commented, but I removed them from the paste
because it is indeed a lot of code for someone to look over.
Looks like as if you should follow the acknowledged programming principle
to split a larger algorithm into smaller chunks (top-down, or bottom-up
programming). This also increases your chance of finding the expression
that causes the memory leak yourself.
[...]
As for ineffiency - are you referring to the repeated occurences of
'skinElement[skinElementID]' instead of replacing them with something
like 'var element = skinElement[skinElementID]', and then using
'element',
For example. Another sign are repeated property accesses to `length' in
`for' statements which can be equally avoided. And a property access to
`length' should not be necessary for XML objects in E4X by the `for each'
control statement. There is also the possibility of an alternative of
comparing boolean values to comparing string values with .toString() ==
"True" or .toString() == "False".
or is there a better approach than switch/case?
There is. You can map one value to another one with an Object object.
If E4X, and therefore an ECMAScript Edition 3 conforming implementation,
is a dependency, instead of
var result = "foo";
switch (x)
{
case "1":
result += "bar";
case "2":
result += "baz";
// ...
default:
result += "blubb";
}
result += "Bar";
you can and should write
var
result = ["foo"],
map = {
"1": "bar",
"2": "baz"
// ...
};
result.push(
(x in map) ? map[x] : "blubb",
"Bar");
result = result.join("") ;
almost always. (Note that this Object object inherits some properties from
Object.prototyp e, but their names are not numeric. If you want or need to
consider those too, for example because a substring can possibly equal the
name of such a property, you will have to use a control statement such as
`switch' instead of the `in' operator. The value of that property will be
pushed to the array instead otherwise. But at least you can avoid the
inefficient stepwise string concatenation of `+='.)
HTH
PointedEars