Subj : Re: Recalculating scope chain (i.e., 'with' statement). To : netscape.public.mozilla.jseng From : Christopher M. Balz Date : Tue May 31 2005 11:12 pm [replying to Brendan Eich; forgot to CC list on first mail; full thread copied below] Thank you. I believe that I understand your explanation. In light of your explanation, the JS 1.5 entry on 'with' at DevMo (http://developer-test.mozilla.org/docs/Core_JavaScript_1.5_Reference:Statements:with) did not seem accurate. So I wrote up the following (below) and posted it there using the Wiki feature. On the other topic, it would be helpful for debugging purposes to capture the activation object. I am not as experienced in Venkmann as I'd like to be, so maybe that is already possible and I just don't know how. Most of my JS debugger experience is with Interdev. Specifcally, sometimes stepping into the right function closure is not practical for time reasons or the closure simply cannot be stepped into as the debugger does not give the opportunity. On Interdev, I have definitely run into situations where I needed to check local variables but a function closure identifier presented a "black box" to me that I couldn't get into. Thanks tons for your help! My entry for 'with' in the "JS Reference" is below: Description JavaScript looks up any unqualified names within the set of statements to determine if the names are properties of the default object specified by the 'with' statment. If an unqualified name matches a property in this default object, then the property is used in the statement. Otherwise, a local or global variable is used. Peformance Pro & Con Pro: 'with' can help reduce file size by reducing the need to repeat an object reference identifier without performance penalty. The scope chain change required by 'with' is not computationally expensive. Use of 'with' will relieve the interpreter of parsing repeated object references. Con: 'with' forces the specified default object to be searched first for all lookups. Therefore all identifiers that match formal function argument and declared local variable names will be found more slowly in a 'with' block. Where performance is important, 'with' would likely only be used to encompass code blocks that do not use function argument and declared local variable identifiers. - Chris B. Christopher M. Balz wrote: > It is said in books of lore that using the 'with' > statement is computationally expensive. But why is > this so, if the scope chain is merely a chain of > object references? Would not using the 'with' > statement merely amount to changing about two > references (that of the child scope, and that of the > parent scope)? Entering and leaving the statement governed by with is not expensive. It's the name lookups inside the with. They must be made at runtime; you cannot optimize a name get or set within a with statement to a stack frame slot for all identifiers that match formal argument and declared local variable names. > Separately, are there any plans to open up access to a > function closure via object references? No. Why do you want to capture the activation object (SpiderMonkey's internal class for this is named Call), exactly? /be Christopher M Balz http://treelogic-swe.com 160 Lincoln Avenue, Palo Alto, CA 94301-2437, USA (h) 650.327.0367 / (w) 650.965.2900x207 cbalz@andrew.cmu.edu christophermbalz@stanfordalumni.org chris@treelogic-swe.com ". . . / This Cabinet is formd of Gold / And Pearl & Crystal shining bright And within it opens into a World / . . . Another England there I saw / Another London with its Tower Another Thames & other Hills / And another pleasant Surrey Bower . . ." - from "The Crystal Cabinet", a poem by William Blake. .