[Javascript] Object reference usage (was Javascript and FF)

Mike Dougherty msd005 at gmail.com
Mon Aug 31 09:02:59 CDT 2009


On Mon, Aug 31, 2009 at 4:07 AM, Paul Novitski<paul at juniperwebcraft.com> wrote:
> 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.

given a tree-like object:
myObjRoot.Region["East"].City["NewYork"].Office["NY315"].Manager["ABC"].Agent["DEF"].FirstName
= "Frank";

should (in your opinion) we do this:
var agent = myObjRoot.Region["East"].City["NewYork"].Office["NY315"].Manager["ABC"].Agent["DEF"];
agent.FirstName = "Frank";

Does it cost anything* to make the variable reference for a single
property assignment?
Does it cost anything* to use the unwieldy but very explicit reference
from root for several assignments?


* cost anything: in terms of resource overhead in memory or CPU such
that would be prohibitive to run inside a loop (for one example of
exacerbating a performance issue)  or is the performance cost
negligible compared to increased  readability of the source?



More information about the Javascript mailing list