|
Posted by Michael Winter on 07/11/05 01:35
On 10/07/2005 16:37, ^reaper^ wrote:
[snip]
> The point *was* you accomplish the same end result. Obviously the
> approach is differnt. One does not even need to know js to see that.
But people less familiar with ECMAScript wouldn't associate one with the
other unless they were shown side-by-side, which was why I did it. It
wasn't for your benefit. :)
> The primary question is, does the browser support it? [...]
Of course.
> if( document.getElementById )return document.getElementById(name).style;
> else if( document.links )return document.links[name].style;
> else if( document.all )return eval('document.all.'+name+'.style');
If you do still use that code, you should swap the order of the links
and all collection branches (as well as replace the eval call). Whilst
IE does support the links collection, you cannot use strings as indices
so you shouldn't allow it to reach that statement. That said, only IE4
would get that far (IE 3 doesn't implement the all collection), so it's
clearly not a concern if you don't care about something that old.
[snip]
>> The alternative to this is to create a large switch statement with each
>> clause containing a separate function call with a finite number of
>> arguments. [...]
>
> Why not simply set the function to accept an array argument?
That's a possible solution if you have control over the called function,
as is using an object.
[snip]
>> Well, part of it seems to be missing [...]
>
> There is no "full code." It was nothing more than speculation in response
> to other psoted code. Though, I did upload both example snippets (as per my
> response to Michael).
I'm Michael. He's Richard. :P
I did find that thread when looking for the original post, but it's a
bit difficult when you don't allow your posts to be archived. ;) Noodles
also seems to have removed his page.
There's a vast amount of redundancy in the original code, and from what
I remember, that's almost entirely due to the markup with which the
script is supposed to interact.
For instance, rather than using groups of radio buttons to determine
over what period the input relates, he seems to have used individual
checkboxes, giving the impression that one must check each one,
producing that massive if..else statement.
As for your code, it is a vast improvement, but it still has its own
redundancy.
The functions all set the output themselves. It would be better if they
returned the value, not only because writing the output would occur in
one place, but it also shouldn't be the responsibility of that
particular code to perform any kind of I/O.
The statements within each clause of the switch statement only really
differ in three ways: multiplication versus division; where the data
comes from; and what arguments are passed to the calculation function.
As I don't like code duplication, I'd probably have the data retrieval
code (for want of a better expression) execute whether the data was
needed or not. The execution time would be marginal anyway. As you'd now
have all of the data, you could just homogenise the interface to each
function and pass the lot. I don't really like that idea though, but
changing the scope of the functions isn't any better, either. The final
issue is also awkward. Perhaps the data could be normalised, or the two
functions that are called later could take the reciprocal of the
relevant argument.
[snip]
>> alt.2600 remains cross-posted purely for your benefit, and perhaps that
>> of OMH.
>
> You wouldn't want teh /Guru/ of teh interweb to miss out on this, would
> you?
Guru? You are still talking about OMH, right?
> Though... you *do* realize he's a t0rll, right? o_O
Of course. He might not be courteous, but I am (usually). :)
[snip]
Mike
--
Michael Winter
Prefix subject with [News] before replying by e-mail.
[Back to original message]
|