[Greasemonkey] Javascript lexical scoping question

Prakash Kailasa pk-moz at kailasa.net
Fri Apr 15 11:16:13 EDT 2005


On Fri, Apr 15, 2005 at 01:54:22AM -0500, Edward Lee wrote:
> 
> Does anyone know why this was mentioned in the Statements section?
> "The with statement should not be used." I've never used it before
> today, but I noticed the javascript shell using it, and I added to it
> with more with statements. It's a nice feature but does pretty much
> the same thing as assigning a variable to that level. Ex. Instead of
> "a.b.c.d.e.x = a.b.c.d.e.y = a.b.c.d.e.z;".. you could do "var tmp =
> a.b.c.d.e; tmp.x = tmp.y = tmp.z;" or  "with(a.b.c.d.e) { x = y = z;
> }"

I was asking the very same question in the #greasemonkey irc channel
yesterday.

I have googled for references to "with statement" being harmful, but
all I could find was this site (www.crockford.com) only. It was
mentioned in five documents on that site, but unfortunately
Mr. Crockford never explained why.

/prakash

-- 
|Linux poses a real challenge for those with a taste for late-night    |
|hacking (and/or conversations with God).                              |
|        -- Matt Welsh                                                 |


More information about the Greasemonkey mailing list