If(x)with(x) What is this?!

travisowens

Centurion
Joined
Feb 11, 2004
Messages
108
Location
Rochester, NY
.
...........RESOLVED (see next post)
.
I'm looking into somebody's Javascript code and I came across this syntax, I have no idea what the if/with line means and Google isn't helping. BTW, this is part of a web control that puts a HELP link on the top right of pages.

C#:
<div id="HelpTopRight" class="HelpTopRight" style="white-space:nowrap;">
	<xsp:HelpLink ID="lnk" runat="server" />
</div>
<script type="text/javascript" language="javascript">
	var x=document.getElementById('HelpTopRight')
	[B]if(x)with(x)[/B]
	{
		style.setExpression('left',document.body.clientWidth-60)
	}
</script>
 
Last edited:
I wouldn't have questioned this at all if I had seen a more formal syntax, such as
C#:
if(x)
{
	with(x)
	{
		style.setExpression('left',document.body.clientWidth-60)
	}
}

I'm outright shocked that with() works outside the brackets.
 
Last edited:
Brackets

Rather than it being a case of with() being outside the brackets, it is a case of the brackets belonging to the with block rather than the if block. Any control structure can be used without brackets - operating on a single statement. For example:

Code:
if (x)
    doThis();

However, that single statement can be another control structure with its own block of code (as in this case).

:)
 
Back
Top