[Javascript] Javascript and FF
Del Wegener
del at delweg.com
Sun Aug 30 08:52:36 CDT 2009
----- Original Message -----
From: "Paul Novitski" <paul at juniperwebcraft.com>
> The following might not be relevant to your problems with Firefox 3.5.2,
> but:
>
but I did notice that your 'with' statements are wonky, e.g.:
>
> with (Math)
> {
> var k = Math.pow(10,place);
> return (Math.round(numb*k))/k;
> }
>
> This code suggests the existence of Math.Math.pow() and
> Math.Math.round(). The whole idea behind 'with' is that you name the
> object up front and omit it in the block, e.g.:
>
> with (Math)
> {
> var k = pow(10,place);
> return (round(numb*k))/k;
> }
>
> cf.
'with' is not particularly efficient. It has to
> check all of the variables & methods in the block to see if they're
> attached to the object in question.
>
> The fact that you're mis-using 'with' isn't going to abort your
> script in Firefox (I just tested one of your with blocks and it ran
> fine), it will just eat up a few buckets of machine cycles while
> JavaScript searches the Math object in vain for nonexistent methods.
> Not a big deal. But it is one sign that your code needs cleaning up,
> and that would be one place to start.
>
Thanks for all of this {Paul;
I did some reading and now I am of the opinion that I should omit the with
function entirely so that
with (Math)
{
var k = pow(10,place);
return (round(numb*k))/k;
}
would be replaced with
var k = Math.pow(10,place);
return (Math.round(numb*k))/k;
Would this be more efficient?
Was there a time in ancient history when the with(Math) {} construction was
advised?
I must have read it is some reference.
Del
More information about the Javascript
mailing list