[Javascript] Javascript and FF
Paul Novitski
paul at juniperwebcraft.com
Mon Aug 31 04:07:15 CDT 2009
At 8/30/2009 06:52 AM, Del Wegener wrote:
>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?
If I understand the documentation correctly, removing 'with' in your
example above would be more efficient for the computer to execute
since using 'with' would force it to consider whether k, pow, place,
round, and numb were Math properties or methods, improving the name
resolution process for only two out of the five names in the block.
Perhaps a more important question is, would using 'with' make the
code faster & easier for a human to read? Unless a particular usage
acutely affects the computer's response time, machine efficiency
should be considered less important than either the functional
benefit it provides (none with 'with') or its human readability and
usability. Programming languages are for the benefit of people, not
computers which would be just as happy, and a whole lot faster,
executing concisely-written machine code.
>Was there a time in ancient history when the with(Math) {} construction was
>advised?
What 'with' really does is place the named object at the beginning of
the list of contexts in which to search for unqualified names. I
think this limits the circumstances in which it would be truly useful
to unusual cases in which a block consists mainly of that object's
properties and methods.
with (dog)
{
feet = 4;
tail = 1;
teeth = 42;
var rescue = find('Timmy');
...
fleas = Infinity;
coprophagia = true;
}
I think 'with' in JavaScript is analagous to the second person
singular pronoun 'thou' in English. It comes in handy once in a blue
moon but it's kind of cute and the language would surely pale were it
ever to be excised.
Regards,
Paul
__________________________
Paul Novitski
Juniper Webcraft Ltd.
http://juniperwebcraft.com
More information about the Javascript
mailing list